Page 1 of 1

refill form options

Posted: Tue Oct 11, 2005 10:04 am
by kristolklp
I have an order form setup with input fields, radio buttons, checkboxes, and comboboxes. My form also contains a 'submit order' button.

When the user clicks 'submit order' my form posts all variables back to the php file and checks for errors (incomplete fields, etc.). If there is an error I want the user selections to stay on the form so they do not have to enter ithe same nformation again. I know how to fill the text fields in with the posted variables, but how do I handle checkboxes, radio buttons, combo boxes, etc.?

Code: Select all

<input type="text" name="name" value="<?php echo $name ?>"  size="20">
Thanks!

Posted: Tue Oct 11, 2005 10:22 am
by feyd
checked="checked" (checkboxes and radio buttons)
selected="selected" (combo boxes)

you'll have to compare the value they chose against each value of each group

Posted: Tue Oct 11, 2005 10:24 am
by shiznatix
just make your form like this

Code: Select all

<input type="text" name="first" value="<?= $_POST['first'] ?>">
<select name="second">
  <option value="somting" <?= ($_POST['second'] == 'somting' ? 'selected' : '') ?>>
</select>
and you should be good if you are not using error_reporting(E_ALL)

edit: i was a bit slow i knew i would be :oops:

Posted: Tue Oct 11, 2005 11:17 am
by Luke

Code: Select all

<input type="text" name="name" value="<?php echo $name ?>"  size="20">
Make sure to use $_POST (or $_GET if you are using a get form)

Using just the variable name is not good.

Posted: Tue Oct 11, 2005 12:12 pm
by kristolklp
Thanks for the help!
Make sure to use $_POST (or $_GET if you are using a get form)

Using just the variable name is not good.
I actually set the variable during my error trapping before it gets back doen to the form.

Posted: Tue Oct 11, 2005 2:51 pm
by mchaggis
Just to add to this (although yiou are setting you vars in the script).

I find that using the $_REQUEST variable works better in situations where you want to pre-submit the form, i.e. a post action to comit, but use a get action to preview before comitting

Just my two pennies worth :D