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
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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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