Forcing a form field to send upper case values to database

10 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: May 21, 2010   (RSS)

By gkornbluth - May 19, 2010

Hi all,

I’m setting up a user profile revision form and I’m stuck trying to submit characters to the database in a particular case.

Everything that I’ve tried so far only displays the case requested in the form but does not send the transformed case value to the user account database.

The original code for the form field was:

<input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" size="50" />

Here’s what I’ve tried so far for all uppercase:

First using strtoupper, I defined a variable as:

<?php $state = htmlspecialchars(@$_REQUEST['state']); ?>

Then in the form field I tried:

<input type="text" name="state" value="<?php echo strtoupper($state); ?>" size="50" />

Next I tried adding style="text-transform:uppercase" to the form field:

<input type="text" name="state" style="text-transform:uppercase" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" size="50" />

I even tried a few JavaScript solutions with the same result.

I'd like to be able to do an initial caps version as well.

Any Ideas?

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Forcing a form field to send upper case values to database

By Djulia - May 19, 2010

Hi Jerry

Test :

<?php echo strtoupper(strtolower(@$_REQUEST['state'])); ?>

Djulia

Re: [Djulia] Forcing a form field to send upper case values to database

By gkornbluth - May 19, 2010

Thanks Djulia,

I'll give it a try and let you know how it turns out.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Forcing a form field to send upper case values to database

By Jason - May 19, 2010

Hi Jerrry,

What you need to do is to transform the variable before adding it to the database, that way the value that it displays in the form doesn't matter.

Before your query to update that database, try this:

$_REQUEST['state']=strtoupper($_REQUEST['state']);

This will take the value of the field "state" from the form, put it to all uppercase, then assign it to $_REQUEST['state']; This value can now be submitted normally to the database.

If you want to just put the first letter to upper case, use this instead:

$_REQUEST['state']=ucfirst($_REQUEST['state']);

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Forcing a form field to send upper case values to database

By gkornbluth - May 19, 2010

Thanks Jason,

I guess I was transforming the text after adding it to the database not before, which would much more sense.

It's always so simple when you know how.

I think it's about time you electioneered to remove the "in training" from your signature.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Forcing a form field to send upper case values to database

By gkornbluth - May 19, 2010

Hi Jason,

I'm sure that the code is OK and I'm missing something, but when I insert
<?php $_REQUEST['state'] = strtoupper($_REQUEST['state']); ?>
into

<tr>
<td class="body-text-bold">State</td>
<td><input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" MAXLENGTH="2" size="50" /></td>
</tr>


Like this:

<tr>
<td class="body-text-bold">State<?php $_REQUEST['state'] = strtoupper($_REQUEST['state']); ?></td>
<td><input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" MAXLENGTH="2" size="50" /></td>
</tr>


I get this error:

Notice: Undefined index: state in /hsphere/local/home/apbcweb/artistsofpalmbeachcounty.org/member_signup7.php on line 212 /code]

Thanks,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Forcing a form field to send upper case values to database

By Jason - May 20, 2010

Hi Jerry,

When putting information into a form, it's usually a good idea to use the @ character, since we can't always guarantee that there is a value in the $_REQUEST array.

Try using this code:

<tr>
<td class="body-text-bold">State<?php @$_REQUEST['state'] = strtoupper(@$_REQUEST['state']); ?></td>
<td><input type="text" name="state" value="<?php echo htmlspecialchars(@$_REQUEST['state']); ?>" MAXLENGTH="2" size="50" /></td>
</tr>


That way nothing will be displayed if there is nothing in that variable.

Is everything else working on the form? Is it inserting correctly into the database? If not, maybe you could attach your whole file and I can take a look.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Forcing a form field to send upper case values to database

By gkornbluth - May 21, 2010

Hi Jason,

Sorry to be the bearer of sticky problems lately.

The error is gone, but if the information is entered into the form in lower case, it gets entered into the database in lower case.

I've attached the file.

Please ignore the Captcha code, it's still a work in progress and I'll post the results in that thread.

Best,

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

member_signup.php 24K

Re: [gkornbluth] Forcing a form field to send upper case values to database

By Jason - May 21, 2010

Hi Jerry,

Your code right now, changes the variable to upper case when it's displaying it, not before it enters it into the database. Try this line before your mysql INSERT statement (Line 42):

@$_REQUEST['state']=strtoupper(@$_REQUEST['state']);

This will change the variable to upper case just before it's entered into the database.

Give this a try and let me know.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Forcing a form field to send upper case values to database

By gkornbluth - May 21, 2010

Whew...

Got it now.

Bet you're glad.

Thanks!

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php