Jump to content

Remember array $_POST values


DarkPrince2005

Recommended Posts

I've got a form that is generated x-amount of times, x being selected from a drop down. But everytime the form is submitted and the  forms don't validate the user has to re-enter all thee data.

Does anyone know how I can make the form remember the $_POST values of an array.

 

e.g. <input value="$_POST["name"]" />

 

<div name="students" id="students">
               <table align=center border=0 cellspacing=4 cellpadding=0 width=700px>
                  <input type="hidden" name="student_tot" value="1">
                  <tr>
                     <td align="left" colspan="4">Student 1: <br><hr></td>
                  </tr> 
                  <tr>
                     <td><FONT color=#ff0000>*</FONT> Title</td>
                     <td width="23%"><?drop_down(array("Mr","Mrs","Miss","Dr","Prof"), "s_title[]");?></td>
                     <td width="27%"><FONT color=#ff0000>*</FONT> Last Name</td>
                     <td width="23%"><input class=FrmTextBox style="width: 100%" name="s_surname[]"></td>
                  </tr> 
                  <tr>
                     <td ><FONT color=#ff0000>*</FONT> First Name</td>
                     <td ><input class=FrmTextBox style="width: 100%" name="s_name[]"></td>
                     <td><FONT color=#ff0000>*</FONT> Birthday</td>
                     <td>
                        <?
                           drop_days1('s_bday[]', date('d',strtotime($date1))); 
                           echo " ";
                           drop_months1("s_bmonth[]", "to_day", $date1); 
                           echo " ";
                           drop_years1("s_byear[]", $date1); 
                        ?>
                     </td>
                  </tr> 
                  <tr>
                     <td>   ID Number</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_ID[]"></td>
                     <td rowspan="2" valign="top"><FONT color=#ff0000>*</FONT> Postal Address</td>
                     <td rowspan="2"><textarea class=FrmTextBox style="width: 100%" name="s_address[]"></textarea></td>
                  </tr> 

                  <tr>

                     <td>   Tel (W)</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_tel_w[]"></td>
                  </tr> 
                  <tr>
                     <td>   Tel (H)</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_tel_h[]"></td>
                     <td>   Fax</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_fax[]"></td>
                  </tr>
                  <tr>
                     <td><FONT color=#ff0000>*</FONT> Email</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_email[]"></td>
                     <td><FONT color=#ff0000>*</FONT> Cell</td>
                     <td><input class=FrmTextBox style="width: 100%" name="s_cell[]"></td>
                  </tr>
               </table>
            </div>

Link to comment
Share on other sites

  • 2 weeks later...

What you need to do is to check if page being displayed after error, or if POST values are set.

lets say we have that code:

drop_down(array("Mr","Mrs","Miss","Dr","Prof"), "s_title[]");

I suppose second parameter is what must be selected in drop down. so lets say what input name of drop down box is 'title'.

Then solution will be:

drop_down(array("Mr","Mrs","Miss","Dr","Prof"), (isset($_POST['name'])?$_POST['name']:"s_title[]") );

or lest say we have variable $error_state what is set to true if we showing page after failed validation:

drop_down(array("Mr","Mrs","Miss","Dr","Prof"), ($error_state?$_POST['name']:"s_title[]") );

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.