3 Replies Latest reply on Apr 18, 2010 6:49 AM by tashmac

    form validation not working

    tashmac

      Hi

       

      I have done form validation through the behaviours but it wont work can someone have a look and tell me why?  The code is below.

       

      Thanks

      Natasha

       

      <?php
              /** Session Variables **/
              session_start();
              ob_start();
             
      if( isset($_POST) && !empty($_POST) )
      {
              /** Include Files **/
              require 'include/dbase.php';

      $sql = "select * from admin_user";

      $res = mysql_query($sql);

      $row = mysql_fetch_array($res);

      $mailto = 'nmcdonald@acornsolutions.ie';

      $from = $_POST['email'];

      $mailsubject = "Download of Brochure ";

      $message =$_POST['forename']. $_POST['surname']. "has requested to download a brochure \n\n\nForename :  ".$_POST['forename']."\nSurname : ".$_POST['surname']."\nTelephone No : ".$_POST['phone']."\nEmail : ".$_POST['email']. "Regards, \n naturalstonecarpet.ie";


      $headers = "From: ". $from."\r\n";
       
      $mail = mail($mailto,$mailsubject,$message,$headers);

      if($mail)
      {
              $msg = m1;
      }
      else
      {
              $msg = m2;
      }


              /** Functionality **/

       
               $sqlins = "insert into Download_a_Brochure (`brochure_id`, `forename`, `surname`, `phone`,`email`, `timestamp`) values ('".mysql_escape_string($_POST['brochure_id'])."', '".mysql_escape_string($_POST['forename'])."', '".mysql_escape_string($_POST['surname'])."', '".mysql_escape_string($_POST['phone'])."', '".mysql_escape_string($_POST['email'])."', '".date("Y-m-d H:i:s")."')";

                      $resins = mysql_query($sqlins) or die(mysql_error());
                      if($resins)
                              $msg = 1 ;
                      else
                              $msg = 2;
                      header("Location: download-brochure.php?msg=".$msg);
         

      exit;
      }

      ?>
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
      <meta name="title" content="Natural stone flooring, flooring suppliers, home flooring, commercial flooring, stone carpet - Natural Stone Carpets FAQs">
      <meta name="keywords" content="Natural stone flooring, flooring suppliers, home flooring, commercial flooring, stone carpet">
      <meta name="description" content="Natural stone flooring, flooring suppliers, home flooring, commercial flooring, stone carpet in Ireland and UK">
      <meta name=" abstract " content="Ireland and UK Natural stone flooring, flooring suppliers, home flooring, commercial flooring, stone carpet">

      <meta name="robots" content="index, follow">
      <meta name="author" content="naturalstonecarpets.ie">
      <meta name="home_url" content="http://www.naturalstonecarpets.ie">
      <meta name="classification" content="Natural stone flooring, flooring suppliers, home flooring, commercial flooring, stone carpet">
      <meta name="revisit-after" content="7 days">
      <meta name="language" content="English">
      <meta name="charset" content="ISO-8859-1">
      <meta name="distribution" content="Global">
      <meta name="rating" content="General">
      <meta name="expires" content="Never">

      <title>Stone Carpet - Home & Commercial Flooring - FAQs</title>
      <link href="nsc-styles.css" rel="stylesheet" type="text/css" media="all" />
      <link rel="stylesheet" href="sIFR-screen.css" type="text/css" media="screen" />
      <link rel="stylesheet" href="sIFR-print.css" type="text/css" media="print" />

      <script src="sifr.js" type="text/javascript"></script>
      <script src="sifr-addons.js" type="text/javascript"></script>
      <script src="sifr-test.js" type="text/javascript"></script>
      <style type="text/css">
      <!--
      .style1 {font-size: 16px}
      -->
      </style>

      <script type="text/JavaScript">
      <!--
      function MM_findObj(n, d) { //v4.01
        var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
          d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
        if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
        for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
        if(!x && d.getElementById) x=d.getElementById(n); return x;
      }

      function MM_validateForm() { //v4.0
        var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
        for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
          if (val) { nm=val.name; if ((val=val.value)!="") {
            if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
              if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
            } else if (test!='R') { num = parseFloat(val);
              if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
              if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
                min=test.substring(8,p); max=test.substring(p+1);
                if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
          } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
        } if (errors) alert('The following error(s) occurred:\n'+errors);
        document.MM_returnValue = (errors == '');
      }
      //-->
      </script>
      </head>
      <body>
      <table id="pagewidth" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td id="header" colspan="3"><div id="banner"><img class="logo" src="images/nsc-logo.jpg" alt="Natural Stone Carpets" />
      <table width="200" border="0" class="original">
                <tr>
                  <td align=""><img src="images/call_us_sample.gif"/></td>
                  <td><span class="style1"><font size="6px" face="Times New Roman, Times, serif" color="#fffac5">call us</font></span></td>
                </tr>
                <tr>
                  <td colspan="2"><span class="style1"><font size="+1" color="#fffac5" face="Times New Roman, Times, serif">+ 353 1 8900111</font></span></td>
                </tr>
              </table></div></td>
        </tr>
        <tr>
          <td class="content" width="180" valign="top"><div id="nav">
              <ul>
                <li><a href="index.html"><font color="#fff3b2" size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Home</strong></font></a></li>
                <li><a href="about.html"><font color="#fff3b2" size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Natural Stone Carpets</strong></font></a></li>
          <li><a href="stone-carpet-marble.html"><font color="#fff3b2" size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Marble Stone Carpets </strong></font></a> <font color="#FF0000"><strong><em>  <img src="images/newicon.gif" /></em></strong></font></li>
                <li><a href="home-flooring.html"><font color="#fff3b2"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Home Flooring</strong></font></a></li>
          <li><a href="commercial-flooring.html"><font color="#fff3b2"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Commercial Flooring</strong></font></a></li>
                <li><a href="gallery.html"><font color="#fff3b2"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Gallery</strong></font></a></li>
                <li><a href="testimonials.html"><font color="#fff3b2"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Client Testimonials</strong></font></a></li>
                <li><a href="faqs.html"><font color="#1fe4e5"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>FAQs</strong></font></a></li>
                <li class="last"><a href="contact.html"><font color="#fff3b2"  size="3px" face="Georgia, Times New Roman, Times, serif"><strong>Contact Us</strong></font></a></li>
              </ul>
            </div>
            <div class="left-button"><a href="6reasons.html"><img src="images/6-reasons.gif" alt="5 Reasons to choose a Natural Stone Carpet" width="150" height="60" /></a></div>
            <div class="left-button"><a href="download.html"><img src="images/pdf-download.gif" alt="Download a PDF Brochure" width="150" height="60" /></a></div>
            <div class="left-button"><a href="http://ie.linkedin.com/in/christopherhyland"><img src="images/natural_stone_link_in.gif" border="0"/></a></font></div></td>
          <td class="content" width="410" valign="top">
            <div id="inside">
          <h1>Download a Brochure </h1>
          <img src="images/shopfloor.jpg" alt="Detail of a Carpet" width="400" height="160" />
           <p><table width="500" border="0" align="center" >
              <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" >
                <tbody>
                  <tr>
                    <td colspan="2" align="center" valign="top"><strong>
                      <?php if($_GET['msg'] == "1") { ?>
                      <a href="http://www.naturalstonecarpets.ie/download.html" target="_self" class="style1">Click here to Download the Brochure</a>
                      <?PHP } elseif($_GET['msg'] == "2") { ?>
      Please enter all field  and try again.
      <?php } ?>
                    </strong></td>
                    </tr>
                  <tr>
                    <td width="129" align="right" valign="top"><p class="style43">First Name
                      </p>
                    </p>                </td>
                    <td width="261" align="left"><input name="forename" onsubmit="MM_validateForm('forename','','R');return document.MM_returnValue" size="20"  /></td>
                  </tr>
                 
                  <tr>
                    <td align="right" valign="top"><p class="style43">Surname</span></td>
                    <td align="left"><input name="surname" onsubmit="MM_validateForm('surname','','R');return document.MM_returnValue" size="20" /></td>
                  </tr>
                 
                  <tr>
                    <td align="right" valign="top"><p class="style43">Phone No:</td>
                    <td align="left"><input name="phone" onsubmit="MM_validateForm('phone','','RisNum');return document.MM_returnValue"   size="20"  /></td>
                  </tr>
                 
                  <tr>
                    <td height="29" align="right" valign="top"><p class="style43">E-mail</span></td>
                    <td height="29" align="left"><span class="style35" style=" font-size:12px">
                      <input name="email" onsubmit="MM_validateForm('email','','RisEmail');return document.MM_returnValue" size="20" />
                    </span></td>
                  </tr>
                 
                  <tr>
                    <td height="29" colspan="2" align="right" class="style35" style=" font-size:12px"> </td>
                  </tr>
                  <tr>
                    <td height="29" colspan="2" align="right" class="style35" style=" font-size:12px"><span class="style35" style=" font-size:12px">
                      <input value="Submit" type="submit" name="brochure" id="brochure" />
                    </span></td>
                  </tr>
                </tbody>
              </form>
      </table>


           </p>
              </div>
          <td class="content" width="180" valign="top">
            <div id="rightcol">
              <div class="right-article">
                <h3>Visit our Showroom</h3>
                <p>Natural Stone Carpets Ltd,<br />
                  Unit 8, Site 1,<br />
                  Swords Business Park,<br />
                  Swords,<br />
                  Co. Dublin.</p>
                <img src="images/arrow-on-white.gif" alt="#" width="9" height="12" /><a href="location.html">View a Location Map</a> </div>
              <div class="right-article-last">
                <h3>How does it work? </h3>
                <p>Find out about the process
                  involved in fitting a Natural
                  Stone Carpet.</p>
                <img src="images/arrow-on-white.gif" alt="#" width="9" height="12" /><a href="process.html">The Process </a> </div>
            </div></td>
        </tr>
        <tr>
          <td id="footer" colspan="3"><ul>
              <li>&copy; Natural Stone Carpets 2010 - Stone Carpet </li>
              <li><a href="sitemap.html">Site Map</a></li>
              <li><a href="privacy.html">Privacy Policy</a></li>
        <li>Site Designed by<a href="http://www.redsky.ie/"> Red Sky</a></li>
            </ul></td>
        </tr>
      </table>


      <script type="text/javascript">
      var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
      </script>
      <script type="text/javascript">
      try {
      var pageTracker = _gat._getTracker("UA-4552857-17");
      pageTracker._trackPageview();
      } catch(err) {}</script>

      </body>
      </html>

        • 1. Re: form validation not working
          Ben M Adobe Community Professional

          I just tried making the same validations using the DW built-in functions and I am getting a different result and am wondering how you got to your conclusion.  By default, when the mm_validation gets added to a form field it seems to be adding to onblur instead of onsubmit which your form is doing.  The onblur would do the validation when the focus is trying to be moved away from the field.  When I add it to the submit button it is adding it to the onclick behavior to execute before the form is submitted.

           

          When you are adding the validation, have you selected the Submit button of your form first or are you clicking on the fields, or are you doing this manually?

          • 2. Re: form validation not working
            tashmac Level 1

            Hi  Yes i originally had onblur but for this to work they have to click

            into the field it doesnt work if no fields are selected and the submit button is clicked

             

            i want all fields to be filled in before the submit button will work that is why i canged it to

            onsubmit.  How do i have the validation checked when submit button is clicked.

             

            Thanks

            Natasha

            • 3. Re: form validation not working
              Ben M Adobe Community Professional

              Using the built in functionality, click on the submit button to put the focus on that.  Then open the Tag Inspector and choose to validate the form.  Here you will have a list of all your form fields and the validation options.  Just go through each field and set the validations as necessary and DW should handle the rest.  It should set the event of the submit button to onclick which activates the action before the form is submitted.  Then you should be good to go.