SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Self submitting Form

    Hi I have a self submitting form and I have a function that is a called to print out errors. Some of the code in the form is below. In the function I put the errors in an array. When I submit the form only two errors are printed out at a time. I want to know why is that if I'm constantly putting my errors in an array only two errors are printed at a time. The form is processing all the errors and will not let the user submit the form with errors but it won't print out all the errors all at once. Can someone help me figure out why only two errors are printed at a time?

    function validate_form()
    {
    if($_POST['Submit']=="Submit")
    {
    $errors=array();

    //Check for errors
    if(! strlen(trim($_POST['name'])))
    {
    $errors[] = "Please enter your name";
    }
    elseif(! strlen(trim($_POST['major'])))
    {
    $errors[] = "Please enter your major";
    }

    >>more and more error checking not included in this snippet<<

    return $errors;
    }

    <?php
    if(isset($_POST['Submit']) && $_POST['Submit']=="Submit")
    {
    $results;
    $results=validate_form();
    if(count($results) == 0)
    {
    process_form();
    }
    else{
    for($i=0; $i<count($results); $i++)
    {
    echo "$results[$i], ";
    }

    }
    }
    >>html code for the form<<
    ?>

  2. #2
    SitePoint Member nabil_kadimi's Avatar
    Join Date
    Nov 2006
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use "if" instead of "elseif"

  3. #3
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks so much

    Thank you sooooooo much!!!! I thought of that but didn't think it would make a difference. Your help is greatly appreciated!

    I have one more question:

    Once all the data is checked then the form calls another function that processes the form. It processes it correctly but I have a redirect and it doesn't process the redirect.

    This is what the function does - It finds out who the email is suppose to go to and then it sends out an HTML email with all the values the user submitted and then it mails the HTML form.

    I don't want to put all that code here so I'll just put the end...

    //send message
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

    mail($to, $subject, $body, $headers, "From: $from");
    mail($to2, $subject, $body, $headers, "From: $from");

    header("Location: http://ksweb.keiseruniversity.edu/graduate_testimonial_submit.php");


Bookmarks

Posting Permissions

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