简体   繁体   中英

Post Form DATA to another page after PHP Validation

I have this issue with my validation and posting the data to another page.

Here is my form:

Signup.php

<form id="regForm" action="<?php echo htmlspecialchars($_SERVER["submit.php"]);?>" method="post" name="regForm">
    <label for="fname">First Name:</label><input name="fname" type="text" size="25" maxlength="35" value="<?php if(isset($_POST['fname'])){echo $_POST['fname'];}?>"/><br/>
    <label for="mdname">Middle initial:</label><input name="mdname" type="text" size="10" maxlength="35" value="<?php if(isset($_POST['mdname'])){echo $_POST['mdname'];}?>"/><br/>
    <label for="lname">Last Name:</label><input name="lname" type="text" size="25" maxlength="35" value="<?php if(isset($_POST['lname'])){echo $_POST['lname'];}?>"/><br/>
    <br/>
    <label>&nbsp;</label><input type="submit" name="Signup" class="formButton" value="Signup" /></form>

And here is my submit.php which will validate the signup.html input

submit.php

function msg($status,$txt)
{
    return '{"status":'.$status.',"txt":"'.$txt.'"}';
}

// we check if everything is filled in and perform checks
//check if fname is empty
if(!$_POST['fname'])
{
    die(msg(0,"<p>Please enter your first name.</p>"));
}
//check if lname is empty
if(!$_POST['lname'])
{
    die(msg(0,"<p>Please enter your last name.</p>"));
}

Now, my issue is this, in my "submit.php" file, I want to know what codes to put after the form fields validation that would enable me post the input data to another page because, I plan making it a two-page signup form. Let's say my next page is signup-2.html

how do I post the data after validation to the next page? I know how to retrieve the posted data on the next page like using Session or Echo the $_POST data but, my main issue is....how do I make the form post the data after the validation messages in my submit.php file?

use header :

header("Location: your page url?fname=$_POST['fname']&lname=$_POST['lname']");

but before this do not echo or print anything otherwise it won't redirect to that page.

you can use the data on destination page like this:

$_GET['fname']

example:

submit.php

function msg($status,$txt)
{
    return '{"status":'.$status.',"txt":"'.$txt.'"}';
}

// we check if everything is filled in and perform checks
//check if fname is empty
if(!$_POST['fname'])
{
    die(msg(0,"<p>Please enter your first name.</p>"));
}
//check if lname is empty
if(!$_POST['lname'])
{
    die(msg(0,"<p>Please enter your last name.</p>"));
}

header('Location:download.php?fname='.$_POST['fname']."&lname=".$_POST['lname']);

view.php

<html>
<body>
<form action="submit.php" method="post">
<input type='text' id="fname" name="fname"/>
<input type='text' id="lname" name="lname"/>
<input type="submit" id="button" value="submit"/>
</form>

</body>


</html>

download.php

<?php
echo "First Name........".$_GET['fname'];

put these three file in same directory and run view.php. you will be ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM