Jump to content


Photo

re-enter details for invalid email address


  • Please log in to reply
3 replies to this topic

#1 seaten

seaten
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 March 2006 - 02:35 PM

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>


#2 php_b34st

php_b34st
  • Members
  • PipPipPip
  • Advanced Member
  • 168 posts

Posted 03 March 2006 - 05:14 PM

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

//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>';

Then replace:

<?
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>
}



?>

with:

<?
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();
}
?>

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.

#3 mainewoods

mainewoods
  • Members
  • PipPipPip
  • Advanced Member
  • 685 posts
  • LocationMaine

Posted 03 March 2006 - 05:20 PM

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:
<input type="Text" name="sel_person_email" value="<?php echo $sel_person_email; ?>">
--notice that I embedded php right inside the value="" statement.

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

//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>


#4 seaten

seaten
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 03 March 2006 - 06:22 PM

cheers guys i will try this out now




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users