Jump to content

Re-Posting data in a form


NickG21

Recommended Posts

i was wondering how exactly i could repost the data that was entered in my form if everything passes through the validation in the script below.  thank you

[code]<html>
<head>
</head>
<body>
<form action="testing1.php" method="post">
<input type="text" name="text1" value="Your Name"><br/>
<input type="text" name="text2" value="Zip" maxlength="5"><br/>
<input type="text" name="email" value-"E-Mail"><br/>
<input type="submit" name="submit" value="submit"><br/>
<input type="hidden" name="submitted" value="1">
</form>
<?php

if ($_POST['submitted'] == 1) {
$email = $_POST['email'];
$name = $_POST['text1'];
$number = $_POST['text2'];

// check e-mail address
// display success or failure message

if (!preg_match("/^([a-zA-Z])+/",$_POST['text1']))
{
echo("Text Only As Your Name, Please Re-Submit");
}
if (!preg_match("/^([0-9])+/",$_POST['text2']))
{
echo("Invalid Number Scheme");
}
if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email']))
{
die("Invalid e-mail address");
}
echo "Valid e-mail address, processing...";
}
$submitted=0;
?>
</body>
</html>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/
Share on other sites

i want to take the validated data and if a different piece didn't pass validation be able to pass the good data back into the form so that the entire form doesn't need to be refilled if there is only one error.  i am starting on a small scale with only these three text boxes but there will be many more before i am complete.  thank you
why dont you do this:
[code]
<html>
<head>
</head>
<body>
<form action="testing1.php" method="post">
Your Name<input type="text" name="text1" value="<?echo"$name"?>"><br/>
Zip code<input type="text" name="text2" maxlength="5" value="<?echo"$number"?>"><br/>
E-mail<input type="text" name="email" value="<?echo"$email"?>"><br/>
<input type="submit" name="submit" value="submit"><br/>
<input type="hidden" name="submitted" value="1">
</form>
<?php

if ($_POST['submitted'] == 1) {
$email = $_POST['email'];
$name = $_POST['text1'];
$number = $_POST['text2'];

// check e-mail address
// display success or failure message

if (!preg_match("/^([a-zA-Z])+/",$_POST['text1']))
{$name = "";
echo("Text Only As Your Name, Please Re-Submit");
}
if (!preg_match("/^([0-9])+/",$_POST['text2']))
{$number = ""
echo("Invalid Number Scheme");
}
if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email']))
{$email = ""
die("Invalid e-mail address");
}
echo "Valid e-mail address, processing...";
}
$submitted=0;
?>
</body>
</html>
[/code]
No, the provided code does what you want it too.

It doesn't put anything in as the value on the first display of the form, but once you've filled the fields in and submitted, the default values will be set to what you put in the fields.

Regards
Huggie

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.