Forum Moderators: coopster

Message Too Old, No Replies

Displaying more user friendly form element names

         

kamkaz

6:36 pm on Mar 8, 2005 (gmt 0)

10+ Year Member



Hi all,
I have a form in my php code like:

<input type="Text" name="First">
<input type="Text" name="Last">
<input type="Text" name="Postal">

and then I pump i t back out on the next page:


foreach($_POST as $name=>$value){
echo"$name = $value<br>";
}

I am wondering if there a property that I can assign the form elements (textboxes, radios, dropdowns) that will display more user friendly names. The foreach loop works for me. There are actually are a lot of form elements

So rather than


First = Kam
Last = Kaz
Postal = 73928

I would like to have:


First Name = Kam
Last Name = Kaz
Zip/Postal Code = 73928

Does anyone know of how to do this without a lot of CASE or IF statements.

Thank you

jusdrum

7:41 pm on Mar 8, 2005 (gmt 0)

10+ Year Member



You can have spaces in your form element names. I'm not sure what other characters are allowed, but spaces help a great deal to make it look more presentable to users.

<input type="text" name="Postal Code" size="30" />

foreach ($_POST as $Name => $Value)
{
echo "$Name = $Value<br />";
}

Postal Code = 90210

Hope this helps!

jatar_k

7:45 pm on Mar 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



why not like so

<input type="Text" name="First_Name">
<input type="Text" name="Last_Name">
<input type="Text" name="Postal_Code">

foreach($_POST as $name=>$value) {
echo str_replace('_',' ',$name)," = $value<br>";
}

kamkaz

3:42 am on Mar 9, 2005 (gmt 0)

10+ Year Member



jusdrum: Thanks. But I thing that if I want to referance the data like $Frist it may be a problem.. I could not get it to work.

jatar_k: This is perfect! I implement this right away.

coopster

12:10 pm on Mar 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That's correct. If you want to use variable variables, you cannot have spaces in the variable [php.net] name.

jusdrum

5:32 pm on Mar 9, 2005 (gmt 0)

10+ Year Member



Good call guys, I didn't even think of that :-)