Announcement

Collapse
No announcement yet.

need help validating forms

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • need help validating forms

    hello there,
    I have been able to create a feed back form which allows me to submit the values from the form to my email address...now i am trying to validate the fields for which i have written a php...but i have a few concerns..for example....if the person enters his name to be empty i am tryng to open a new html page in which all the fields of the earlier feedback form are displayed along with which it displas a messag to enter an emial id...in the process the rest of the values entered should not go to my email its only when the validation for all the fields is done the values go to my email address..in the meantime every field needs to be validated and any of the mandatory fields left empty it should display a new window giving the message to enter vallues in that particular field..i have written the php but i dont know where do i insert this php code...many thanks
    chandni

  • #2
    Re: need help validating forms

    Look at http://www.vodahost.com/vodatalk/for...html#post26480

    It does what you want without opening new windows. I think that you have also tested my form, so you have seen how it works.
    Navaldesign
    Logger Lite: Low Cost, Customizable, multifeatured Login script
    Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
    DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
    Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

    Comment


    • #3
      Re: need help validating forms

      <?PHP
      error_reporting(7);
      #----------
      # Validate: String
      function check_string($value, $low, $high, $mode, $optional)
      {
      if ( (strlen($value) == 0) && ($optional === true) ) {
      return true;
      } elseif ( (strlen($value) >= $low) && ($mode == 1) ) {
      return true;
      } elseif ( (strlen($value) <= $high) && ($mode == 2) ) {
      return true;
      } elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == 3) ) {
      return true;
      } else {
      return false;
      }
      }
      #----------
      # Validate: Email
      function check_email($email, $optional)
      {
      if ( (strlen($email) == 0) && ($optional === true) ) {
      return true;
      } elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
      return true;
      } else {
      return false;
      }
      }
      #----------
      # Validate: Equal to field
      function check_equalto($original, $repeated)
      {
      if ($original == $repeated) {
      return true;
      } else {
      return false;
      }
      }
      # RegisterGlobals OFF
      $FTGrequiredname = $_POST['requiredname'];
      $FTGrequiredemail = $_POST['requiredemail'];
      $FTGrequiredconfirm = $_POST['requiredconfirm'];
      $FTGmessage = $_POST['message'];
      $FTGnewsletter = $_POST['newsletter'];
      $FTGReset = $_POST['Reset'];
      $FTGsubmit = $_POST['submit'];
      # Fields Validations
      $validationFailed = false;
      if ( (! check_string($FTGrequiredname, 1, 0, 1, true))) {
      $validationFailed = true;
      }
      if ( (! check_email($FTGrequiredemail, false))) {
      $validationFailed = true;
      }
      if ( (! check_equalto($FTGrequiredconfirm, $FTGrequiredemail))) {
      $validationFailed = true;
      }
      if ( (! check_string($FTGmessage, 1, 0, 1, true))) {
      $validationFailed = true;
      }
      # Redirect user to the error page
      if ($validationFailed == true) {
      header("Location: http://www.to your errorpage/error.php");
      exit;
      }
      # Email to Form Owner
      $emailTo = '"email name here" <your email address here';
      $emailSubject = "Contact information Sent";
      $emailBody = "" . $_SERVER['HTTP_USER_AGENT'] . " " . $_SERVER['REMOTE_ADDR'] . " " . date('Y-m-d H:i:s') . "\n"
      . "\n"
      . "\n"
      . "The following information has been sent from your text here\n"
      . "\n"
      . "Name: $FTGrequiredname\n"
      . "\n"
      . "Email:\n"
      . "\n"
      . "email: $FTGrequiredemail\n"
      . "confirm: $FTGrequiredconfirm\n"
      . "\n"
      . "\n"
      . "Message: \n"
      . "\n"
      . "$FTGmessage\n"
      . "\n"
      . "\n"
      . "Newsletter Sign-Up yes/no: $FTGnewsletter\n"
      . "\n"
      . "\n"
      . "";
      $emailHeader = "From: $FTGrequiredemail\n"
      . "Reply-To: $FTGrequiredemail\n"
      . "MIME-Version: 1.0\n"
      . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
      . "Content-transfer-encoding: quoted-printable\n";
      mail($emailTo, $emailSubject, $emailBody, $emailHeader);
      # Confirmation Email to User
      $confEmailTo = $FTGrequiredemail;
      $confEmailSubject = "Thank You";
      $confEmailBody = "Hello $FTGrequiredname\n"
      . "\n"
      . "Thank You for contacting etc\n"
      . "\n"
      . "We will be in touch soon.\n"
      . "\n"
      . "www.your web site\n"
      . "\n"
      . "";
      $confEmailHeader = "From: email address here\n"
      . "Reply-To: email address here\n"
      . "MIME-Version: 1.0\n"
      . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
      . "Content-transfer-encoding: quoted-printable\n";
      mail($confEmailTo, $confEmailSubject, $confEmailBody, $confEmailHeader);
      # Redirect user to success page
      header("Location: http://www.toyoursuccesspage/success.php");
      exit;
      # End of PHP script
      ?>

      here copy of php I use alot, you will need to change the "FTG" to the name of your boxes on your form. This script will check box to make sure they are filled in and the email address is vaild etc.

      If you need any help the above code just let me know.

      you can see it working at www.bluevodaexchangelink.com/contact/contact.php
      www.bluevodaexchangelink.com
      BluevodaExchangeLink Help Center
      Bluevodaexchangelink Forum

      The only place for bluevoda site to be linked with!

      Comment


      • #4
        Re: need help validating forms

        I am not sure that this is the right place fo rmy message. i am a newbie, having just created a small business website using Vodablue and Vodahost. I have created a simple sign-in form requesting visitor name and email. The submit button takes them to a resource page where they can download articles and documents. I used the php script at the bottom of the form tutorial1.
        The problem is that the submit button works whether visitors enter their name and email or not. So the purpose of the form to build a subscriber list is defeated.
        How do I validate the two ffields I have created on my form: name and email? I tried improvising on the script by reading some of the posts on this forum and could not make it work. Here is what I did:
        <?PHP
        $email = $HTTP_POST_VARS[email];
        $mailto = "info@askartsolutions.com";
        $mailsubj = "Resource Sign In";
        $mailhead = "From: $email\n";
        reset ($HTTP_POST_VARS);
        $mailbody = "Visitor name and email address:\n";
        while (list ($key, $val) = each ($HTTP_POST_VARS))
        {
        $mailbody .= "$key : $val\n";
        }
        mail($mailto, $mailsubj, $mailbody, $mailhead);
        ?>


        <?php
        // Receiving variables from the form
        @$name = addslashes($_POST['name']);
        @$email = addslashes($_POST['email']);
        // Validation for empty fields and email
        if (strlen($name) == 0 )
        {
        header("Location: name_errorpage.html");
        exit;
        }

        if (strlen($email) == 0 )
        {
        header("Location: email_errorpage.html");
        exit;
        }
        //Sending Email to form owner
        $pfw_header = "From: $email\n"
        . "Reply-To: $email\n";
        $pfw_subject = "Resource Sign In";
        $pfw_email_to = "
        info@askartsolutions.com";
        *****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
        header("Location: articlepage.html");
        ?>


        Like I said, the first php works, but when i added the second php, I messed up and nothing worked. Please take a ook and tell me what I am doing wrong?

        Regards,
        Art
        askartsolutions.com

        Comment


        • #5
          Re: need help validating forms

          Originally posted by askartiso
          I am not sure that this is the right place fo rmy message. i am a newbie, having just created a small business website using Vodablue and Vodahost. I have created a simple sign-in form requesting visitor name and email. The submit button takes them to a resource page where they can download articles and documents. I used the php script at the bottom of the form tutorial1.
          The problem is that the submit button works whether visitors enter their name and email or not. So the purpose of the form to build a subscriber list is defeated.
          How do I validate the two ffields I have created on my form: name and email? I tried improvising on the script by reading some of the posts on this forum and could not make it work. Here is what I did:
          <?PHP
          $email = $HTTP_POST_VARS[email];
          $mailto = "info@askartsolutions.com";
          $mailsubj = "Resource Sign In";
          $mailhead = "From: $email\n";
          reset ($HTTP_POST_VARS);
          $mailbody = "Visitor name and email address:\n";
          while (list ($key, $val) = each ($HTTP_POST_VARS))
          {
          $mailbody .= "$key : $val\n";
          }
          mail($mailto, $mailsubj, $mailbody, $mailhead);
          ?>


          <?php
          // Receiving variables from the form
          @$name = addslashes($_POST['name']);
          @$email = addslashes($_POST['email']);
          // Validation for empty fields and email
          if (strlen($name) == 0 )
          {
          header("Location: name_errorpage.html");
          exit;
          }

          if (strlen($email) == 0 )
          {
          header("Location: email_errorpage.html");
          exit;
          }
          //Sending Email to form owner
          $pfw_header = "From: $email\n"
          . "Reply-To: $email\n";
          $pfw_subject = "Resource Sign In";
          $pfw_email_to = "
          info@askartsolutions.com";
          *****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
          header("Location: articlepage.html");
          ?>


          Like I said, the first php works, but when i added the second php, I messed up and nothing worked. Please take a ook and tell me what I am doing wrong?

          Regards,
          Art
          Take the validate part of the script above and place in the top of your php script. you will need to eith add an "error" part or an "error" page, there are many differant way to do what you want. if you don't what to to it in php check the script (by view source) www.bluevodaexchangelink.com/contact/contact.php, try sending the form which email and see what happens, if you want this script let me know.
          www.bluevodaexchangelink.com
          BluevodaExchangeLink Help Center
          Bluevodaexchangelink Forum

          The only place for bluevoda site to be linked with!

          Comment


          • #6
            Re: need help validating forms

            Thanks Maddog for your help.
            I checked your form and it is exactly what I want - to send visitors to an error page if they put invalid emails. I also want to have their names and emails sent to my email address and for them to be directed to my resource page once they enter a valid email on my form.

            I tried your suggestion to put the validate part of the script in the top of the php script (see below) and created an error.html page. The sign in works with a valid email; but invalid email sign-ins still go to my resources page. The only new part now is that if somebody clicks the submit button without entering anything at all, I get the following error message:

            Warning: Cannot modify header information - headers already sent by (output started at /home/clpqlxhu/public_html/articles.php:7) in /home/clpqlxhu/public_html/articles.php on line 28


            Here is my revised script following your advice:

            <script language="php">
            // Receiving variables from the form
            @$name = addslashes($_POST['name']);
            @$email = addslashes($_POST['email']);
            // Validation for empty fields and email
            if (strlen($name) == 0 )
            {
            header("Location:error.html");
            exit;
            }
            if (strlen($email) == 0 )
            {
            header("Location:error.html");
            exit;
            }
            //Sending Email to form owner
            $pfw_header = "From: $email\n"
            . "Reply-To: $email\n";
            $pfw_subject = "Resource Sign In";
            $pfw_email_to = "info@askartsolutions.com";
            *****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
            header("Location: articles.php");
            $email = $HTTP_POST_VARS[email];
            $mailto = "info@askartsolutions.com";
            $mailsubj = "Sign In Form";
            $mailhead = "From: $email\n";
            reset ($HTTP_POST_VARS);
            $mailbody = "Name and email address from Sign in form:\n";
            while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
            if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
            </script>


            I like your form, but I only have two variables (name and email) to be entered. I don't know anything about html programming, so am afraid to tinker. If I can just get the script to do what you have, I would be overjoyed. I have been fiddling with this for a day and half now.
            Any help would be deeply appreciated.
            Regards,
            Art
            askartsolutions.com

            Comment


            • #7
              Re: need help validating forms

              Originally posted by askartiso
              Thanks Maddog for your help.
              I checked your form and it is exactly what I want - to send visitors to an error page if they put invalid emails. I also want to have their names and emails sent to my email address and for them to be directed to my resource page once they enter a valid email on my form.

              I tried your suggestion to put the validate part of the script in the top of the php script (see below) and created an error.html page. The sign in works with a valid email; but invalid email sign-ins still go to my resources page. The only new part now is that if somebody clicks the submit button without entering anything at all, I get the following error message:

              Warning: Cannot modify header information - headers already sent by (output started at /home/clpqlxhu/public_html/articles.php:7) in /home/clpqlxhu/public_html/articles.php on line 28


              Here is my revised script following your advice:

              <script language="php">
              // Receiving variables from the form
              @$name = addslashes($_POST['name']);
              @$email = addslashes($_POST['email']);
              // Validation for empty fields and email
              if (strlen($name) == 0 )
              {
              header("Location:error.html");
              exit;
              }
              if (strlen($email) == 0 )
              {
              header("Location:error.html");
              exit;
              }
              //Sending Email to form owner
              $pfw_header = "From: $email\n"
              . "Reply-To: $email\n";
              $pfw_subject = "Resource Sign In";
              $pfw_email_to = "info@askartsolutions.com";
              *****($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
              header("Location: articles.php");
              $email = $HTTP_POST_VARS[email];
              $mailto = "info@askartsolutions.com";
              $mailsubj = "Sign In Form";
              $mailhead = "From: $email\n";
              reset ($HTTP_POST_VARS);
              $mailbody = "Name and email address from Sign in form:\n";
              while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
              if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
              </script>


              I like your form, but I only have two variables (name and email) to be entered. I don't know anything about html programming, so am afraid to tinker. If I can just get the script to do what you have, I would be overjoyed. I have been fiddling with this for a day and half now.
              Any help would be deeply appreciated.
              Regards,
              Art
              whats the name of the boxes on your form i.e name, email ?
              www.bluevodaexchangelink.com
              BluevodaExchangeLink Help Center
              Bluevodaexchangelink Forum

              The only place for bluevoda site to be linked with!

              Comment


              • #8
                Re: need help validating forms

                Do you have MSN or SKYPE , if so contact me and I will try and talk you thought it.
                www.bluevodaexchangelink.com
                BluevodaExchangeLink Help Center
                Bluevodaexchangelink Forum

                The only place for bluevoda site to be linked with!

                Comment


                • #9
                  Re: need help validating forms

                  Hi Maddog,
                  The box names on the forms are; name and email.
                  You can contact me directly at: artjlewis@rogers.com
                  Email me your telephone # and I will call you directly. If I can lick this problem today, it will be more than worth it.
                  Thanks
                  I am in Toronto, Canada
                  Regards,
                  Art
                  askartsolutions.com

                  Comment


                  • #10
                    Re: need help validating forms

                    Hello all,
                    I would like to commend Maddog for his assistance and tremendous patience in walking me through the numerous iterations of getting my Sign-In form to work. My form works perfectly now.
                    Thanks Maddog!!
                    Art
                    askartsolutions.com

                    Comment

                    Working...
                    X