Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2006
    Posts
    1

    Unanswered: email validation back to original form

    Howdy - I'm primarily a web designer and have only recently begun using PHP with mySQL databases.

    I've got two forms: form1.php which contains an email field, the action on the form leads to form2.php, which actually posts the data into the dbase. I've found some code that will do a general validation for my email field, and have placed it in form2.php. I know I need to tell it to validate the field and if it is false, then return to form1.php without losing any of the user-entered data in all the other fields. I'm not very good with syntax yet, and can't get my head around how to do this. Here is the code for the email validation:

    function validate_email($email) {

    if( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) ) {
    return true;
    }
    else {
    return false;
    $warning="<div class\"whiteEight\">Please enter a valid email address</div>"
    }

    }
    Can anyone help me out? persheate it.

  2. #2
    Join Date
    Apr 2004
    Posts
    50
    You can make the first page to post to itself and make the email validation a JavaScript client-side function. If you do it this way, the form will not be submitted at all if the validation fails.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off you email validation may fail, as virtually any character can be used prior to the @ eg apostrophes

    javascript validations are fine and dandy, unless the viewer has turned off javascript. if you can build it in, then fine, agree it reduces the traffic to and from the server. However you still have to validate the incoming data on the server

    just guessing you have succesfully passed the values to a validation script
    normally I'd put in the validation script an error flag

    if the error flag is true then call the user input form, otherwise call another script you can set the parameters for the url

    PHP Code:
    if (errorflag == TRUE)
    $target "http://myurl.com/UserInput.php";
    } else
    $target "http://myurl.com/PostValidationform.php";
    }
    $Params" ?Param1=$param1&Param2=$param2
    header("
    Location$target$Params"); 
    if you set the parameter fields to the the same as the name property you set in your user input script then they will appear there.

    note you should reference the script parameters as $_GET['paramname'] / $_POST['paramname']
    Last edited by healdem; 10-17-06 at 16:23.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •