This topic is locked
[SOLVED]

 Remove space from beginning of data field

12/13/2019 7:13:03 PM
PHPRunner General questions
M
mhollibush author

Good Evening,

I am running into an issue where end users are "copy and pasting" data into a field that is creating a space or are putting a space at the beginning of their entry.

How can I remove the space before the data prior to saving the data to the database...

Its causing lookup and duplicate entries issues.

K
keithh0427 12/13/2019

Use 'trim' function the "Before record added" for the Add page and "Before record updated" on the Edit page.
For example on the add page: $values['country'] == trim($values['country'])
On the edit page, use: $values['country'] == trim($values['country']) // assuming they are editing the field name in question.

If they aren't editing it, you could use something like this:
if ( $values['country'] == '' )

$values['country'] == trim($oldvalues['country']) // This gets any existing fields with spaces and may be redundant if the field is already trimmed
Of course, use your field name, not my example (country)_

M
mhollibush author 12/14/2019



Use 'trim' function the "Before record added" for the Add page and "Before record updated" on the Edit page.
For example on the add page: $values['country'] == trim($values['country'])
On the edit page, use: $values['country'] == trim($values['country']) // assuming they are editing the field name in question.

If they aren't editing it, you could use something like this:
if ( $values['country'] == '' )

$values['country'] == trim($oldvalues['country']) // This gets any existing fields with spaces and may be redundant if the field is already trimmed
Of course, use your field name, not my example (country)_


Thank you for pointing me in the right direction.
I figured it out... only use one "="

I was using "==" as you showed, this is where I was lost - no errors, but also didn't remove the spaces...
$values['product'] = trim($values['product']); ( removes spaces from the field )

$values['prod_descript'] = ltrim($values['prod_descript']); ( removes beginning spaces from the field )