Passing form data from one web page to another with PHP

15,800

I would say for security reasons, do not use Get method "$_GET[]" as people described, keep POST as you have it.

All you need to do on register/ page is get all the values passed on using the POST method and populate them into your HTML. So the second form should look like:

    <form id="register" name="form1" method="post" action="send_contact.php">
    <fieldset>  
    <li><label>First Name</label>
    <input type="text" id="first_name" name="first_name" value="<?=$_POST[first_name]?>" />
    </li>

    <li>
    <label>*Last Name</label>
    <input type="text" id="last_name" name="last_name" value="<?=$_POST[last_name]?>" />
    </li>

    <li>
    <label>*Email</label>
    <input type="text" id="email" name="email" value="<?=$_POST[email]?>" />
    </li>

    <li>
    <label>*Confirm Email</label>
    <input type="text" id="confirm-email" name="confirm_email" />
    </li>

    <li>
    <label>Street Address</label>
    <input type="text" id="address" name="address" value="<?=$_POST[address]?>" />

    <li class="full-width">
    <input id="submit" type="submit" value="Register" />                    
    </li>

    </fieldset>
    </form> 

Above, I am using shorthand version of "echo" and php tags, if you do not have that enabled under php.ini, please change "" to "; ?>. Also, script will not populate "confirm" email as I assume you would like the user to retype that.

That should do it.

Share:
15,800
Ad Reactor
Author by

Ad Reactor

Updated on June 14, 2022

Comments

  • Ad Reactor
    Ad Reactor almost 2 years

    i found few similar questions here but from answers i didn't get the whole picture of how should work.

    I have a subscription form in a page:

    <form method="post" action="index.php/register"> 
    <fieldset> 
    <input type="text" id="first_name" name="first_name" /> 
    <input type="text" id="last_name" name="last_name" />
    <input type="text" id="email" name="email" />
    <input type="text" id="address" name="address" /> 
    <input id="submit" type="submit" value="&gt;&gt;" /> 
    </fieldset> 
    </form>
    

    when a user a user click the submit button is lead to a page with the full registering form, where i need to have few fields populated with the data sent from previous page form. this is a preview of few fields from the form of the second page:

    <form id="register" name="form1" method="post" action="send_contact.php">
    <fieldset>  
    <li><label>*First Name</label>
    <input type="text" id="first_name" name="first_name" />
    </li>
    
    <li>
    <label>*Last Name</label>
    <input type="text" id="last_name" name="last_name" />
    </li>
    
    <li>
    <label>*Email</label>
    <input type="text" id="email" name="email" />
    </li>
    
    <li>
    <label>*Confirm Email</label>
    <input type="text" id="confirm-email" name="confirm_email" />
    </li>
    
    <li>
    <label>Street Address</label>
    <input type="text" id="address" name="address" />
    
    <li class="full-width">
    <input id="submit" type="submit" value="Register" />                    
    </li>
    
    </fieldset>
    </form> 
    

    the php is not my strong point, so if you can be more detailed in answer is great for me.

    thanks!

  • Ad Reactor
    Ad Reactor over 12 years
    hi sherif, not working. the fields from page 2 show for instance: " first_name" instead the data from first form.