Jump to content

re-enter details for invalid email address


seaten

Recommended Posts

Hi I'm pretty new to php,

Okay what I'm trying to do is, after the user enters an invalid email address, I want him to re-enter the details for it. I know this sounds pretty simple, but I'm having difficulty with this.

This is my code so far:

//the user enters details
<?


session_start();

session_register('person_name');
session_register('person_email');
session_register('person_phoneno');

?>

<HTML>


<BODY>



<FORM method="post" ACTION="CheckWizard1.php">

Contact name:<input type="Text" name="sel_person_name" value=""><br>
Contact email:<input type="Text" name="sel_person_email" value=""><br>
Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br>


<input type="Submit" name="submit" value="Details">

</FORM>


</BODY>

</HTML>
----------------------------------------------------------------------------------------------------------

//Now I will check if the input is valid(in that case go to wizard2.php, if invalid go back to wizard1.php and re-enter details

//This is code for CheckWizard1.php

<?


session_start();

?>

<HTML>

<?
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email)) {
echo "$person_email is not a valid email";
//go back to wizard1, but I cannot put HTML link here
<P>Please go to final Submit<a href="wizard1.php"> now </a>.</p>
}



?>

//else if everything is valid go post details to wizard2.php


<FORM method="post" ACTION="wizard2.php">

Contact name:<input type="Text" name="sel_person_name" value=""><br>
Contact email:<input type="Text" name="sel_person_email" value=""><br>
Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br>


<input type="Submit" name="submit" value="Details">

</FORM>
Link to comment
Share on other sites

You could put the form into a variable and then call the variable again, try:

[code]//make the forma variable
$form = '<FORM method="post" ACTION="CheckWizard1.php">
    Contact name:<input type="Text" name="sel_person_name" value=""><br>
    Contact email:<input type="Text" name="sel_person_email" value=""><br>
    Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br>
    <input type="Submit" name="submit" value="Details">
    </FORM>';[/code]

Then replace:

[code]<?
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email)) {
echo "$person_email is not a valid email";
//go back to wizard1, but I cannot put HTML link here
<P>Please go to final Submit<a href="wizard1.php"> now </a>.</p>
}



?>
[/code]

with:

[code]<?
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email))
{
    echo $person_email.'is not a valid email<br />'
         .$form;
    exit();
}
?>[/code]

Also i dont think the rest of the script will work the way you wanted it too, it will just print another form rather than sending the data to the 2nd wizard, you might want to combine the two scripts into one.
Link to comment
Share on other sites

The easiest way to reenter field values entered by the user into the <form> fields when validation of the field(s) fails is to put your <form>, your field validation logic, and your <form> processing logic all in the same page.
Untimitely this allows you to do stuff like this:
[code]<input type="Text" name="sel_person_email" value="<?php echo $sel_person_email; ?>">[/code]
--notice that I embedded php right inside the value="" statement.

--To put it all on one page, structure it like this:

[code]//test for submittall of your form:
if (isset($_POST['submit'])) { //the name of your submit button
    //retrieve the form field values
    $sel_person_email = isset($_POST['sel_person_email']) ? $_POST['sel_person_email'] : '';
    //...
    
    //validation logic goes here
    if ($fieldsareOK) {
        //code to store fields in database
        //either do a redirect at this point or instead zero out the data
        //fields for reentry of a new record
        $sel_person_email = '';
        //...
    } //end if
} //end if
//your form goes here
<form    >
//redisplay fields contents if validation failed
<input type="Text" name="sel_person_email" value="<?php echo $sel_person_email; ?>">
//...
</form> [/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.