troubleshooting Question

PHP form validation write var to form?

Avatar of burnedfaceless
burnedfaceless asked on
PHP
3 Comments1 Solution327 ViewsLast Modified:
I've written the following code to ensure that the form has been completely filled out, and that a valid email address has been entered in the email box. The PHP loads HTML with an appropriate header. I kind of like this approach more than JavaScript. Is there any way that I can write the values of the form variables to the new .html page that loads so that the user can still see what they input?

<?php

      function check_email($email)
      {
            $result = TRUE;
            if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email)) {
            $result = FALSE;
      }
  return $result;
}

      //$jaime = "private@domain.com";
      //$kim = "email@domain.com";
      //$pat =  email2@domain.com";
      $subject = "Customer message";
      $first = $_POST['fname'];
      $last = $_POST['lname'];
      $from = $_POST['email'];
      $addy = $_POST['address'];
      $reason = $_POST['ts'];
      $message = $_POST['comments'];
      
      $c = 0;
      
      if (strlen($first) > 0)
      {
            $c++;
      }
      if (strlen($last) > 0)
      {
            $c++;
      }
      if (strlen($from) > 0)
      {
            $c++;
      }
      if (strlen($addy) > 0)
      {
            $c++;
      }
      if (strlen($reason) > 0)
      {
            $c++;
      }
      if (strlen($message) > 0)
      {
            $c++;
      }
      
      if ($c == 6) //all forms are filled out
      {
            
            $body = "From: $first $last\n E-Mail: $from\n Address: $addy\n Reason: $reason\n Message: $message";
            if (check_email($from) == false) //invalid email address
            {
                  header('Location: ../ive.html'); //invalid email address the only problem
            }
            else if (check_email($from) == true) //valid email address. confirmation page
            {
                  //mail($jaime, $subject, $body);
                  //mail($kim, $subject, $body);
                  //mail($pat, $subject, $body);
                  mail($abe, $subject, $body);
                  header('Location: ../thankyou.html');
            }
      }
      
      else if ($c<6)
      {
            if (strlen($from) > 0)
            {
                  if (check_email($from) == true) //valid email with incomplete form.
                  {
                        header('Location: ../cb.html');
                  }
                  if (check_email($from) == false) //invalid email address with incomplete form
                  {
                        header('Location: ../cbf.html');
                  }
            }
            if (strlen($from) == 0) //blank email address input
            {
                  header('Location: ../cb.html');
            }
      }

?>

Thanks
ASKER CERTIFIED SOLUTION
merwetta1

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros