71 users online (1 members and 70 guests)  


  Results 1 to 4 of 4

Related

  1. FormMail.pl    Forum: CGI Perl Forum
    Replies: 4
  2. Replies: 2
  3. problem with formmail script.    Forum: CGI Perl Forum
    Replies: 1
  4. Formmail help    Forum: CGI Perl Forum
    Replies: 1
  5. FORMMAIL Problem    Forum: ASP Forum
    Replies: 1
  1. #1
    ephi's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2007
    Posts
    1

    Unhappy PHP formmail problem

    Hi, I am quite new to php. I have a little problem with my php mail script and I would be very grateful if someone can help me with it. I am setting up a feedback page for a client.
    The mail function works quite well,it sends the mail, but I also need the script to validate the form fields (especially the email field, and to check that the "name" field is not empty).
    Can you suggest how to do it please? I am really confused and need help.
    Here is the form mail code:

    Code:
    <?
    
    if(sizeof($_POST)) {
    $body = "";
    
    foreach ($_POST as $key=>$val) 
    { 
    $body .= "$key: $val \n";
    } 
    
    if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", 
    
    $email)){
    echo "Please enter a valid email address.";
    }
    
    mail("xxxxx@xxxxxxx.com", // to
    "New Submission From Your Website",
    $body, "From: XXXXXXXXX <submissions@xxxxxxx>");
    
    echo "<h4>Thank you. We have received your information.</h4>";
    echo "Please click the back button to return to the page";
    
    }
    else{
            echo "<h5>There was an error in submission</h2>";
            echo "Please resubmit your information";
            echo "Please click the back button to return to the page";
    }
    
    ?>
    The validation just doesn't work. I want it to show any error message, one the same page as the form, so that the user does not have to keep loading the page again each time there is an error.

    I would be very grateful if someone can help me with this.
    Last edited by vinyl-junkie; 08-09-2007 at 10:32 PM. Reason: Added code tags

  2. #2
    fric's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Apr 2007
    Location
    Mauritius
    Posts
    25

    Re: PHP formmail problem

    The best way i see to do this on same page is to use label inside div and then show or hide it depending on the validation instead of using in echo. But you must use javascript for this. Or if you still want to use echo, can use some frame or iframe to dispay the error message.

  3. #3
    ahmedzain's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Posts
    1

    Thumbs up Re: PHP formmail problem

    Thanks So much 4 that .....

  4. #4
    dcuerrier's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2007
    Location
    Brossard, Quebec, Canada
    Posts
    13

    Re: PHP formmail problem

    You may use Javascript to make you validation, empty field, and use divname.innerHTML = "Your html code"; to modify the html content of a div. So the page will note reload.



Tags for this Thread