Page 1 of 1

php form problem...

Posted: Thu Jun 24, 2010 11:57 pm
by rgcreativeweb
Hi All,

questions is , on one page, there is zip code field with 'continue' button below it.

On other page, other form fields are , first name, last name, address, email and zip code fields with submit button.

What I want to do:

When customer enters zip code on first page and press continue button, the zip code field on other page already takes value from first page and customer enters remaining information and press submit button, so that all data goes into mysql database.

Could anyone help, how to do this?

Kind Regards

Re: php form problem...

Posted: Fri Jun 25, 2010 5:30 am
by rahulzatakia
hi, check out the following code which will solve your problem

File : form1.php

Code: Select all


<form id="form1" name="form1" method="post" action="form2.php">
  Zip Code : <label>
  <input type="text" name="zip" />
  </label>
  <label>
  <input type="submit" name="Submit" value="Submit" />
  </label>
</form>

File : form2.php

Code: Select all


<form id="form2" name="form2" method="post" action="">
  <table width="50%" border="1">
    <tr>
      <td><label>First Name </label></td>
      <td><label>
        <input name="fname" type="text" id="fname" />
      </label></td>
    </tr>
    <tr>
      <td>Last Name </td>
      <td><label>
        <input name="lname" type="text" id="lname" />
      </label></td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label>
        <input name="address" type="text" id="address" />
      </label></td>
    </tr>
    <tr>
      <td>City</td>
      <td><label>
        <input name="city" type="text" id="city" />
      </label></td>
    </tr>
    <tr>
      <td>Zip Code </td>
      <td><label>
        <input name="zipcode" type="text" id="zipcode" value="<?=$_POST['zip']; ?>"/>
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="submit" name="Submit2" value="Submit" />
      </label></td>
    </tr>
  </table>
</form>


Re: php form problem...

Posted: Fri Jun 25, 2010 5:34 am
by davex
Hi,

first.php

Code: Select all

<form action="second.php" method="post">
Zip Code: <input type="text" name="zip"> <input type="submit" value="Proceed">
</form>
second.php

Code: Select all

<form action="complete.php" method="post">
All other fields....
<?php
echo "Zip Code: ";
echo "<input type=\"text\" name=\"zip\" value=\"".$_REQUEST['zip']."\">";
?>
<input type="submit" value="Complete">
</form>
Should do the trick. Be warned though the above very simple example is open to abuse as the contents of zip aren't validated which they should be before being output to the screen let alone be written to a database without being sanitised.

HTH,

Cheers,

Dave.

Re: php form problem...

Posted: Fri Jun 25, 2010 12:51 pm
by Jonah Bron
You really should put the zip input box on the same page as the other stuff. There are very few situations where multi-page forms should be used. This probably isn't one of them.

Cheers