Universal Form Validator PHP Support Product Page

In progress

Minimum Required validation conflicts with captcha function

Reported 10 May 2011 17:10:00
1
has this problem
10 May 2011 17:10:00 Simon Howell posted:
I have a form that works fine for all the validation rules in combination with a captcha function I add until I add the minimum required rule to a group of check boxes. When I add this rule the form bypasses all the validations and triggers the captcha function immediately.

You can test the form here:
mars-electric.com/forms/testforma.php

You will see the validation briefly appear then it goes to the captcha function at the bottom of the page. If I remove the minimum required rule from the check boxes it works fine.

Here is my code - it includes the Webassist Email form as well:
<?php error_reporting(7); if ($_GET['hdwtest']=='captchainstalled') { echo 'Captcha verification code installed.'; exit; } if (count($_POST) > 0 || count($_GET) > 4) { @session_start(); foreach ($_GET as $item => $value)@setcookie ('hdw_'.$item, (is_array($value)?implode(",",$value):str_replace("\'","'",$value)), 0, '/');foreach ($_POST as $item => $value)@setcookie ('hdw_'.$item, (is_array($value)?implode(",",$value):str_replace("\'","'",$value)), 0, '/');foreach ($_COOKIE as $item => $value)	  if (substr($item,0,4) == 'hdw_' && $_GET[substr($item,4)] == '' && $_POST[substr($item,4)] == '')@setcookie ($item, '', 0, '/'); if ((empty($_POST['hdcaptcha']) || $_POST['hdcaptcha'] == '' || strtolower($_POST['hdcaptcha']) != strtolower($_SESSION['rand_code'])) && (empty($_GET['hdcaptcha']) || $_GET['hdcaptcha'] == '' || strtolower($_GET['hdcaptcha']) != strtolower($_SESSION['rand_code']))) {if ($_POST['hdwfail'] != '')header('Location: '.$_POST['hdwfail']);else	header('Location: '.$_GET['hdwfail']);exit;} foreach ($_COOKIE as $item => $value) if (substr($item,0,4) == 'hdw_')@setcookie ($item, '', 0, '/'); } reset($_POST);reset($_GET); ?>
<?php require_once('../ScriptLibrary/dmxValidator.php'); ?>
<?php
// Universal Form Validator PHP 1.5.5
$dmxval1 = new dmxValidator();
$dmxval1->script_folder = "../ScriptLibrary";
$dmxval1->cs_validate_on_change = true;
$dmxval1->cs_validate_on_submit = true;
$dmxval1->reenable_javascript = true;
$dmxval1->use_bot_check = false;
$dmxval1->report_type = 0;
$dmxval1->error_font =  "Georgia";
$dmxval1->error_font_size = 10;
$dmxval1->error_color = "#FF0000";
$dmxval1->error_bold = false;
$dmxval1->error_italic = true;
$dmxval1->error_image = "";
$dmxval1->error_fixed = "Custom";
$dmxval1->error_padding = 4;
$dmxval1->border_size = 1;
$dmxval1->border_color = "#FF0000";
$dmxval1->border_style = "solid";
$dmxval1->css_hint_file = "validatorHint5";
$dmxval1->hint_preset = "blue.txt";
$dmxval1->hint_tooltip_position = "top";
$dmxval1->hint_border_color = "#0099ff";
$dmxval1->hint_border_style = "solid";
$dmxval1->hint_bg_color = "#003399";
$dmxval1->hint_text_color = "#ffffff";
$dmxval1->hint_text_font = "Arial";
$dmxval1->hint_text_size = 12;
$dmxval1->hint_text_bold = false;
$dmxval1->hint_text_italic = false;
$dmxval1->hint_box_width = 200;
$dmxval1->hint_image = "";
$dmxval1->hint_fixed = "Custom";
$dmxval1->hint_padding = 4;
$dmxval1->use_custom_focus_class = "fixed";
$dmxval1->focus_border_style = "groove";
$dmxval1->focus_border_size = 0;
$dmxval1->focus_border_color = "#C3D9FF";
$dmxval1->focus_bg_color = "#FFFFFF";
$dmxval1->focus_text_color = "#000000";
$dmxval1->use_custom_valid_class = "fixed";
$dmxval1->valid_border_style = "groove";
$dmxval1->valid_border_size = 2;
$dmxval1->valid_border_color = "#00FF00";
$dmxval1->valid_bg_color = "#FFFFFF";
$dmxval1->valid_text_color = "#000000";
$dmxval1->use_custom_invalid_class = "fixed";
$dmxval1->invalid_border_style = "groove";
$dmxval1->invalid_border_size = 2;
$dmxval1->invalid_border_color = "#FF0000";
$dmxval1->invalid_bg_color = "#FFFFFF";
$dmxval1->invalid_text_color = "#000000";
$dmxval1->add_rule("form1", "Company", "allformats", ",,", "true", "Please enter your company name", "Company Name", "", "");
$dmxval1->add_rule("form1", "Name", "allformats", ",,", "true", "Please enter your name", "Your Name", "", "");
$dmxval1->add_rule("form1", "City", "allformats", ",,", "true", "Please enter your city", "Your City", "", "");
$dmxval1->add_rule("form1", "Telephone", "allformats", ",,", "true", "Please enter your phone number", "Phone", "", "");
$dmxval1->add_rule("form1", "Email", "emailcond", ",,", "true", "Please enter your e-mail address", "E-mail Address", "", "");
$dmxval1->add_rule("form1", "Address1", "allformats", ",Signup,== Yes", "true", "Please enter your address so we can send you our newsletter", "Street Address", "2", "containerAddress1,fade,normal");
$dmxval1->add_rule("form1", "Address2", "allformats", ",Signup,== Yes", "false", "", "Suite/Apt#", "2", "containerAddress2,fade,normal");
$dmxval1->add_rule("form1", "City2", "allformats", ",Signup,== Yes", "true", "Please enter your city so we can send you our newsletter", "City", "2", "containerCity2,fade,normal");
$dmxval1->add_rule("form1", "State", "allformats", ",Signup,== Yes", "true", "Please enter your state so we can send you our newsletter", "State", "2", "containerState,fade,normal");
$dmxval1->add_rule("form1", "Zip", "allformats", ",Signup,== Yes", "true", "Please enter your zip so we can send you our newsletter", "Zip", "2", "containerZip,fade,normal");
$dmxval1->add_rule("form1", "reason[]", "minrequiredcond", "1,,", "true", "Please select at least one option", "", "", "");
$dmxval1->add_mask("form1", "Telephone", "phone", "North America");
$dmxval1->add_mask("form1", "Zip", "zipcode", "United States");
$dmxval1->validate();
?>
<?php require_once("../webassist/email/mail_php.php"); ?>
<?php require_once("../webassist/email/mailformatting_php.php"); ?>
<?php
if (!isset($_SESSION))session_start();
if (($_SERVER["REQUEST_METHOD"] == "POST"))     {
  //WA Universal Email object="mail"
  set_time_limit(0);
  $EmailRef = "waue_testforma_1";
  $BurstSize = 200;
  $BurstTime = 1;
  $WaitTime = 1;
  $GoToPage = "thankyou.html";
  $RecipArray = array();
  $StartBurst = time();
  $LoopCount = 0;
  $TotalEmails = 0;
  $RecipIndex = 0;
  // build up recipients array
  $CurIndex = sizeof($RecipArray);
  $RecipArray[$CurIndex] = array();
  $RecipArray[$CurIndex ][] = "showell@esc-online.com";
  $TotalEmails += sizeof($RecipArray[$CurIndex]);
  $RealWait = ($WaitTime<0.25)?0.25:($WaitTime+0.1);
  $TimeTracker = Array();
  $TotalBursts = floor($TotalEmails/$BurstSize);
  $AfterBursts = $TotalEmails % $BurstSize;
  $TimeRemaining = ($TotalBursts * $BurstTime) + ($AfterBursts*$RealWait);
  if ($TimeRemaining < ($TotalEmails*$RealWait) )  {
    $TimeRemaining = $TotalEmails*$RealWait;
  }
  $_SESSION[$EmailRef."_Total"] = $TotalEmails;
  $_SESSION[$EmailRef."_Index"] = 0;
  $_SESSION[$EmailRef."_Remaining"] = $TimeRemaining;
  while ($RecipIndex < sizeof($RecipArray))  {
    $EnteredValue = is_string($RecipArray[$RecipIndex][0]);
    $CurIndex = 0;
    while (($EnteredValue && $CurIndex < sizeof($RecipArray[$RecipIndex])) || (!$EnteredValue && $RecipArray[$RecipIndex][0])) {
      $starttime = microtime_float();
      if ($EnteredValue)  {
        $RecipientEmail = $RecipArray[$RecipIndex][$CurIndex];
      }  else  {
        $RecipientEmail = $RecipArray[$RecipIndex][0][$RecipArray[$RecipIndex][2]];
      }
      $EmailsRemaining = ($TotalEmails- $LoopCount);
      $BurstsRemaining = ceil(($EmailsRemaining-$AfterBursts)/$BurstSize);
      $IntoBurst = ($EmailsRemaining-$AfterBursts) % $BurstSize;
      if ($AfterBursts<$EmailsRemaining) $IntoBurst = 0;
      $TimeRemaining = ($BurstsRemaining * $BurstTime * 60) + ((($AfterBursts<$EmailsRemaining)?$AfterBursts:$EmailsRemaining)*$RealWait) - (($AfterBursts>$EmailsRemaining)?0:($IntoBurst*$RealWait));
      if ($TimeRemaining < ($EmailsRemaining*$RealWait) )  {
        $TimeRemaining = $EmailsRemaining*$RealWait;
      }
      $CurIndex ++;
      $LoopCount ++;
      session_commit();
      session_start();
      $_SESSION[$EmailRef."_Index"] = $LoopCount;
      $_SESSION[$EmailRef."_Remaining"] = round($TimeRemaining);
      session_commit();
      wa_sleep($WaitTime);
      include("../webassist/email/waue_testforma_1.php");
      $endtime = microtime_float();
      $TimeTracker[] =$endtime - $starttime;
      $RealWait = array_sum($TimeTracker)/sizeof($TimeTracker);
      if ($LoopCount % $BurstSize == 0 && $CurIndex < sizeof($RecipArray[$RecipIndex]))  {
        $TimePassed = (time() - $StartBurst);
        if ($TimePassed < ($BurstTime*60))  {
          $WaitBurst = ($BurstTime*60) -$TimePassed;
          wa_sleep($WaitBurst);
        }
        else  {
          $TimeRemaining = ($TotalEmails- $LoopCount)*$RealWait;
        }
        $StartBurst = time();
      }
      if (!$EnteredValue)  {
        $RecipArray[$RecipIndex][0] =  mysql_fetch_assoc($RecipArray[$RecipIndex][1]);
      }
    }
    $RecipIndex ++;
  }
  $_SESSION[$EmailRef."_Total"] = 0;
  $_SESSION[$EmailRef."_Index"] = 0;
  $_SESSION[$EmailRef."_Remaining"] = 0;
  session_commit();
  session_start();
  if ($GoToPage!="")     {
    header("Location: ".$GoToPage);
  }
}
?>
<!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Mars</title>
<link href="../Styles/form_clean.css" rel="stylesheet" type="text/css" />
<link href="../css/mars.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../Styles/dmxValidator/validatorHint5.css" type="text/css" />
<script type="text/javascript" src="../ScriptLibrary/jsvat.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery-latest.pack.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery.inputHintBox.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery.maskedinput-1.2.2.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery.validate.min.js"></script>
<script type="text/javascript" src="../ScriptLibrary/dmx.jquery.validate.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery.tooltip.min.js"></script>
<script type="text/javascript" src="../ScriptLibrary/jquery.hoverIntent.min.js"></script>
<?php
// dmxValidatorJSStart
$dmxval1->generate_javascript_and_css();
// dmxValidatorJSEnd
?>
</head>

<body>
<form id="form1" name="form1" method="post" action="" class="clean">
  <h3>Contact Mars Electric</h3>
  <ol>
    <li>
      <fieldset>
        <ol>
          <li>
            <label for="Company">Company Name</label>
            <input type="text" id="Company" name="Company" value="<?php echo dmxSetValue("", "Company") ?>" />
            <?php $dmxval1->generate_error("form1","Company","requiredcond",",,");$dmxval1->generate_error("form1","Company","allformats",",,");?>
          </li>
          <li>
            <label for="Name">Your Name</label>
            <input type="text" id="Name" name="Name" value="<?php echo dmxSetValue("", "Name") ?>" />
            <?php $dmxval1->generate_error("form1","Name","requiredcond",",,");$dmxval1->generate_error("form1","Name","allformats",",,");?>
          </li>
          <li>
            <label for="City">Your City</label>
            <input type="text" id="City" name="City" value="<?php echo dmxSetValue("", "City") ?>" />
            <?php $dmxval1->generate_error("form1","City","requiredcond",",,");$dmxval1->generate_error("form1","City","allformats",",,");?>
          </li>
          <li>
            <label for="Telephone">Phone</label>
            <input type="text" id="Telephone" name="Telephone" value="<?php echo dmxSetValue("", "Telephone") ?>" />
            <?php $dmxval1->generate_error("form1","Telephone","requiredcond",",,");$dmxval1->generate_error("form1","Telephone","allformats",",,");?>
          </li>
          <li>
            <label for="Email">E-mail Address</label>
            <input type="text" id="Email" name="Email" value="<?php echo dmxSetValue("", "Email") ?>" />
            <?php $dmxval1->generate_error("form1","Email","requiredcond",",,");$dmxval1->generate_error("form1","Email","emailcond",",,");?>
          </li>
          <li>
            <label for="reason" style="margin-bottom: 10px">Reason for contacting Mars <span class="emph">(Check all that apply)</span></label>
            <div>
              <label style="margin-bottom: 5px">
                <input type="checkbox" name="reason[]" value="Sales" id="Sales"   <?php echo dmxSetCheckbox("Sales", "reason[]") ?> />
                Sales</label>
              <label style="margin-bottom: 5px">
                <input type="checkbox" name="reason[]" value="Lighting Center" id="LightingCenter"   <?php echo dmxSetCheckbox("Lighting Center", "reason[]") ?> />
                Lighting Center</label>
              <label style="margin-bottom: 5px">
                <input type="checkbox" name="reason[]" value="Technical Support" id="TechnicalSupprt"   <?php echo dmxSetCheckbox("Technical Support", "reason[]") ?> />
                Technical Support</label>
              <label style="margin-bottom: 5px">
                <input type="checkbox" name="reason[]" value="Customer Service" id="CustomerService"   <?php echo dmxSetCheckbox("Customer Service", "reason[]") ?> />
                Customer Service</label>
              <label style="margin-bottom: 5px">
                <input type="checkbox" name="reason[]" value="Setup an Account" id="SetupAccount"   <?php echo dmxSetCheckbox("Setup an Account", "reason[]") ?> />
                Setup an Account</label>
              <?php $dmxval1->generate_error("form1","reason[]","requiredcond","1,,");$dmxval1->generate_error("form1","reason[]","minrequiredcond","1,,");?>
            </div>
          </li>
          <li>
            <label for="Comments">Additional Comments</label>
            <textarea id="Comments" name="Comments" style="height: 50px"><?php echo dmxSetValue("", "Comments") ?></textarea>
          </li>
          <li>
            <div>
              <input type="checkbox" name="Signup" value="Yes"  <?php echo dmxSetCheckbox("Yes", "Signup") ?> />
              <label for="Signup" class="inline">Yes, I would like to receive the Mars newsletter and any special offers, events and promotions</label>
            </div>
          </li>
          <div id="containerAddress1">
            <p>So that we can mail our newsletter to you, please provide your complete address.</p>
            <li>
              <label for="Address1">Street Address</label>
              <input type="text" id="Address1" name="Address1" value="<?php echo dmxSetValue("", "Address1") ?>" />
              <?php $dmxval1->generate_error("form1","Address1","requiredcond",",Signup,== Yes");$dmxval1->generate_error("form1","Address1","allformats",",Signup,== Yes");?>
            </li>
          </div>
          <div id="containerAddress2">
            <li>
              <label for="Address2">Suite/Apt#</label>
              <input type="text" id="Address2" name="Address2" value="<?php echo dmxSetValue("", "Address2") ?>" />
              <?php $dmxval1->generate_error("form1","Address2","requiredcond",",Signup,== Yes");$dmxval1->generate_error("form1","Address2","allformats",",Signup,== Yes");?>
            </li>
          </div>
          <div id="containerCity2">
            <li>
              <label for="City2">City</label>
              <input type="text" id="City2" name="City2" value="<?php echo dmxSetValue("", "City2") ?>" />
              <?php $dmxval1->generate_error("form1","City2","requiredcond",",Signup,== Yes");$dmxval1->generate_error("form1","City2","allformats",",Signup,== Yes");?>
            </li>
          </div>
          <div id="containerState">
            <li>
              <label for="State">State</label>
              <input type="text" id="State" name="State" value="<?php echo dmxSetValue("", "State") ?>" />
              <?php $dmxval1->generate_error("form1","State","requiredcond",",Signup,== Yes");$dmxval1->generate_error("form1","State","allformats",",Signup,== Yes");?>
            </li>
          </div>
          <div id="containerZip">
            <li>
              <label for="Zip">Zip</label>
              <input type="text" id="Zip" name="Zip" value="<?php echo dmxSetValue("", "Zip") ?>" />
              <?php $dmxval1->generate_error("form1","Zip","requiredcond",",Signup,== Yes");$dmxval1->generate_error("form1","Zip","allformats",",Signup,== Yes");?>
            </li>
          </div>
        </ol>
        <div class="leftCol250"><img src="/HDWFormCaptcha/FormCaptcha.php?width=180&amp;height=60&amp;letter_count=5&amp;min_size=35&amp;max_size=45&amp;noise=200&amp;noiselength=5&amp;bcolor=ffffff&amp;border=000000" width="180" height="60" id="captchaimg" alt="security code" border="0" /><br />
Enter Security Code:<br />
<input type="text" size="20" name="hdcaptcha" id="hdcaptcha" value="<?php echo dmxSetValue("", "hdcaptcha") ?>" />
<br />
<?php if (isset($_GET["hdwmsg"]) && $_GET["hdwmsg"] == "invalid") echo chr(60)."font color=red".chr(62)."Please, enter the correct security code.".chr(60)."/font".chr(62); ?>
<script type="text/javascript">function HDW_getCookie(name){  var cname = name + "=";var dc = document.cookie; dc = dc.replace(/\+/g," "); if(dc.length > 0) {begin = dc.indexOf(cname); if (begin != -1) {begin += cname.length; end = dc.indexOf(";", begin); if(end == -1) end = dc.length; var rt = dc.substring(begin, end);  return unescape(rt); } } return null;}try {var items = document.getElementsByTagName("input");for(i=0;i < items.length;i++)if (items[i].name != "hdcaptcha" && items[i].name != "hdwfail" )try{var ck = HDW_getCookie("hdw_"+items[i].name);if (ck != "" && ck != null){if (items[i].type == "checkbox")items[i].checked = true;else if (items[i].type == "radio" && items[i].value == ck)items[i].checked = true; else items[i].value = ck;}} catch (e) {}var items = document.getElementsByTagName("select");for(i=0;i < items.length;i++)try{var ck = HDW_getCookie("hdw_"+items[i].name);if (ck != "" && ck != null){for (j=0;j < items[i].length;j++)if (items[i].options[j].value == ck)items[i].selectedIndex = j;  }} catch (e) {}var items = document.getElementsByTagName("textarea");for(i=0;i < items.length;i++)try{var ck = HDW_getCookie("hdw_"+items[i].name);if (ck != "" && ck != null)items[i].value = ck;} catch (e) {}} catch (e) {}</script></div>
        <div class="rightCol450">
          <p class="legal" style="margin: 0">Mars Electric will never share, sell, or rent individual personal information with anyone for their promotional use without your advance permission or unless ordered by a court of law. Information submitted to us is only available to employees managing this information for purposes of contacting you or sending you emails based on your request for information, and to contracted service providers for purposes of providing services relating to our communications with you.</p>
        </div>
      </fieldset>
    </li>
  </ol>
  <input type="reset" value="CANCEL" />
  <input type="submit" value="OK" />
  <input type="hidden" name="hdwfail" id="hdwfail" value="testforma.php?hdwmsg=invalid" />
</form>

</body>
</html>




Replies

Replied 11 May 2011 16:42:14
11 May 2011 16:42:14 Simon Howell replied:
I read elsewhere on the forum that the extension doesn't play well with captcha so I cheated and used Spry validation just for the check box group. Not the most efficient solution, but it works for now.
Replied 31 May 2011 18:03:08
31 May 2011 18:03:08 Miroslav Zografski replied:
Hello Simon,

Unfortunately that is so. However we are in undergoing process of updating the validator. Also we are considering to include a captcha in the new version. So stay tooned.

Regards,

Reply to this topic