php form problem...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rgcreativeweb
Forum Newbie
Posts: 1
Joined: Thu Jun 24, 2010 11:45 pm

php form problem...

Post 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
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

Re: php form problem...

Post 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>

davex
Forum Contributor
Posts: 101
Joined: Sat Feb 27, 2010 4:10 pm
Location: Namibia

Re: php form problem...

Post 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.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: php form problem...

Post 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
Post Reply