Greywacke Posted July 26, 2013 Share Posted July 26, 2013 (edited) hi there, the following validation function is no longer working - it is supposed to halt submission if any of the conditions met, evaluates to false. function validate(frm) { var selcfg = false; var selunq = false; var selnam = frm.text_formname.value; var selarr = new Array(frm.text_formurls.value.split("|")); var selurl = true; for (var i = 0; i < frm.list_copyfrom.options.length; i++) { if (frm.list_copyfrom.options[i].selected) { selcfg = true; break; } } for (var i = 0; i < frm.list_copyfrom.options.length; i++) { if (selnam.toLowerCase()==frm.list_copyfrom.options[i].text.toLowerCase()) { selunq = true; break; } } for (var i = 0; i < selarr.length; i++) { var urlregex = new RegExp("^(http://|https://){1}([0-9A-Za-z]+.)"); if (!urlregex.test(selarr[i])) { selurl = false; } } if (!selcfg) { alert("At least one form needs torbe selected to copy from."); frm.list_copyfrom.focus(); return false; } if (frm.menu_formservice.selectedIndex < 1) { alert("Please select a service forrthe new form configuration to use."); frm.menu_formservice.focus(); return false; } if (frm.text_formname.value.length < 5) { alert("Please enter a formnamerlonger than 4 chars in length."); frm.text_formname.focus(); return false; } if (selunq) { alert("Please enter a form name whichris unique regardless of casing."); frm.text_formname.focus(); return false; } if (frm.text_formurls.value=="") { alert("All url's specified need torbe valid, including protocol."); frm.text_formurls.focus(); return false; } if (!sellurl) { alert("All url's specified need torbe valid, including protocol."); frm.text_formurls.focus(); return false; } if (frm.menu_copyfrmcfg1.selectedIndex < 1) { alert("Please select a Form Configuration Dataset!"); frm.menu_copyfrmcfg1.focus(); return false; } if (frm.menu_copyfrmcfg2.selectedIndex < 1) { if (!confirm("Certain to populate Fields Requested manually?")) { frm.menu_copyfrmcfg2.focus(); return false; } } if (frm.menu_copyfrmcfg3.selectedIndex < 1) { if (!confirm("Certain to populate Field Translations manually?")) { frm.menu_copyfrmcfg3.focus(); return false; } } if (frm.menu_copyfrmcfg4.selectedIndex < 1) { if (!confirm("Certain to populate Form Extentions manually?")) { frm.menu_copyfrmcfg4.focus(); return false; } } if (frm.menu_copyfrmcfg5.selectedIndex < 1) { if (!confirm("Certain to populate Get Expected Values manually?")) { frm.menu_copyfrmcfg5.focus(); return false; } } return true;} however - it does not behave as expected. this "wizard" is on an htaccess protected .php page, the contents of which are as follows. <?phpinclude("includes/content/performatix.php");$echo = "";if (isset($_POST["list_copyfrom"]) && isset($_POST["menu_formservice"]) && isset($_POST["text_formname"])) { // request copy headers $copyfrom = $_POST["list_copyfrom"]; $formservice = $_POST["menu_formservice"]; $formname = $_POST["text_formname"]; $formurls = $_POST["text_formurls"]; $formid = 0; // request copy subsets $copyfrmcfg = array(6); $copyfrmcfg[1] = intval($_POST["menu_copyfrmcfg1"]); $copyfrmcfg[2] = intval($_POST["menu_copyfrmcfg2"]); $copyfrmcfg[3] = intval($_POST["menu_copyfrmcfg3"]); $copyfrmcfg[4] = intval($_POST["menu_copyfrmcfg4"]); $copyfrmcfg[5] = intval($_POST["menu_copyfrmcfg5"]); // process copy subsets if ($copyfrmcfg[1]>0) { // Copy Form Configuration Datasets (Creates $formid required in fieldsets below) $tsql2 = "INSERT INTO 32_webformconfigs (bigint_FormService, tinyint_FormDefault, text_FormName, text_FormWebLocation, text_FormLogo, text_WebFormTAFUrl, text_WebFormTAFImage, text_FormMailerFromName, text_FormMailerFromAddress, text_FormHandlerInclude, text_Redirect, tinyint_GetMethod, text_LoadingAnimation, text_ElementPrefix, text_ElementSuffix) SELECT ".$formservice." AS bigint_FormService, tinyint_FormDefault, "".mysql_real_escape_string($formname)."" AS text_FormName, text_FormWebLocation, text_FormLogo, text_WebFormTAFUrl, text_WebFormTAFImage, text_FormMailerFromName, text_FormMailerFromAddress, text_FormHandlerInclude, text_Redirect, tinyint_GetMethod, text_LoadingAnimation, text_ElementPrefix, text_ElementSuffix FROM 32_webformconfigs WHERE bigint_FormID = ".$copyfrmcfg[1].";"; $result2 = mysql_query_errors($tsql2, $conn, __FILE__, __LINE__); $formid = mysql_insert_id($conn); } if ($copyfrmcfg[2]>0 && $formid > 0) { // Copy Fields Requested (Fields Requested, requires formid from first fieldset) $tsql3 = "INSERT INTO 33_webformdetails (bigint_FormID, text_DetailDescription, text_DetailValue) SELECT ".$formid." AS bigint_FormID, text_DetailDescription, text_DetailValue FROM 33_webformdetails WHERE bigint_FormID = ".$copyfrmcfg[2]." AND text_DetailDescription = "FIELD";"; $result3 = mysql_query_errors($tsql3, $conn, __FILE__, __LINE__); } elseif ($copyfrmcfg[3]>0 && $formid > 0) { // Copy Field Translations (Field Translation, requires formid from first fieldset) $tsql4 = "INSERT INTO 33_webformdetails (bigint_FormID, text_DetailDescription, text_DetailValue) SELECT ".$formid." AS bigint_FormID, text_DetailDescription, text_DetailValue FROM 33_webformdetails WHERE bigint_FormID = ".$copyfrmcfg[2]." AND text_DetailDescription = "TRANS";"; $result4 = mysql_query_errors($tsql4, $conn, __FILE__, __LINE__); } elseif ($copyfrmcfg[4]>0 && $formid > 0) { // Copy Form Extentions (vTiger/Leads360 Population, requires formid from first fieldset) $tsql5 = "INSERT INTO 33_webformdetails (bigint_FormID, text_DetailDescription, text_DetailValue) SELECT ".$formid." AS bigint_FormID, text_DetailDescription, text_DetailValue FROM 33_webformdetails WHERE bigint_FormID = ".$copyfrmcfg[2]." AND (text_DetailDescription = "VTIGR OR text_DetailDescription = "L360F");"; $result5 = mysql_query_errors($tsql5, $conn, __FILE__, __LINE__); } elseif ($copyfrmcfg[5]>0 && $formid > 0) { // Copy Get Expected Date (Variable Name & Variable Values & Offsets, requires formid from first fieldset) $tsql6 = "INSERT INTO 33_webformdetails (bigint_FormID, text_DetailDescription, text_DetailValue) SELECT ".$formid." AS bigint_FormID, text_DetailDescription, text_DetailValue FROM 33_webformdetails WHERE bigint_FormID = ".$copyfrmcfg[2]." AND (text_DetailDescription = "GEDAT OR text_DetailDescription = "GEDVO");"; $result6 = mysql_query_errors($tsql6, $conn, __FILE__, __LINE__); } // if errors print them in formatted text if (count($GLOBALS["sql"])) { $echo = "<pre>".print_r($GLOBALS["sql"],true)."</pre>"; } else { header('Location: http://www.performatix.co/production/1000.php'); }}?><!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>Form Config Wizard</title><script language="javascript"><!--// above function goes herefunction loadformconfigs(frm) { var opt = new Array(); var sel = frm["list_copyfrom"]; frm.menu_copyfrmcfg1.options.length = 1; frm.menu_copyfrmcfg2.options.length = 1; frm.menu_copyfrmcfg3.options.length = 1; frm.menu_copyfrmcfg4.options.length = 1; frm.menu_copyfrmcfg5.options.length = 1; for (var i = 0; i < sel.options.length; i++) { opt[i] = new Array(); for (var o = 1; o <= 5; o++) { opt[i][o] = document.createElement("option"); if (sel.options[i].selected) { var to = frm["menu_copyfrmcfg"+o]; //alert(to.name); opt[i][o] = document.createElement("option"); opt[i][o].text = sel.options[i].text; opt[i][o].value = sel.options[i].value; opt[i][o].selected = false; try { to.add(opt[i][o], null); // standards compliant; doesn't work in IE } catch (ex) { to.add(opt[i][o]); // IE only } } } }}//--!></script></head><body><?php echo $echo; ?><form action="" method="post" enctype="multipart/form-data" name="frmwiz" onsubmit="return validate(this);"><fieldset><legend><strong>Required Form Configuration Values</strong></legend><?php$tsql0 = "SELECT * FROM 32_webformconfigs WFC ORDER BY WFC.bigint_FormService, WFC.bigint_FormID;";$result0 = mysql_query_errors($tsql0, $conn, __FILE__, __LINE__);?><label for="list_copyfrom"><strong>Copy From: </strong> <select name="list_copyfrom" id="list_copyfrom" multiple="multiple" size="10" style="width: 256px;" onmouseup="return loadformconfigs(this.form);"><?phpif ($result0) { while ($row = mysql_fetch_assoc($result0)) { echo "<option value="".$row["bigint_FormID"]."">".$row["text_FormName"].(($row["tinyint_FormDefault"]==1)?" (Default)":"")."</option>rn"; } mysql_free_result($result0);}?></select></label><br /><br/><?php$tsql1 = "SELECT * FROM 2_servicescatalogue SC ORDER BY SC.bigint_ServiceID ASC;";$result1 = mysql_query_errors($tsql1, $conn, __FILE__, __LINE__);?><label for="menu_formservice"><strong>For Service: </strong> <select name="menu_formservice" id="menu_formservice" size="1" style="width: 256px;"><option value=""></option><?phpif ($result0) { while ($row = mysql_fetch_assoc($result1)) { echo "<option value="".$row["bigint_ServiceID"]."">".$row["text_ServiceDescription"]."</option>rn"; } mysql_free_result($result0);}?></select></label><br/><br/><label for="text_formname"><strong>For Form Name: </strong> <input name="text_formname" id="text_formname" type="text" value="" style="width: 256px;" /></label><br/><br/><label for="text_formurls"><strong>From URL's ( | delimited): </strong> <input name="text_formurls" id="text_formurls" type="text" value="" style="width: 256px;" /></label></fieldset> <br/><fieldset><legend><strong>Form Configuration Datasets</strong> (Creates <em>$formid</em> required in fieldsets below):</legend><label for="menu_copyfrmcfg1">Base Upon: <select name="menu_copyfrmcfg1" id="menu_copyfrmcfg1" size="1" style="width: 256px; height: 18px;"><option value="0"><-- MANUAL POPULATION --></option></select></label></fieldset> <br/><fieldset><legend><strong>Fields Requested</strong> (Requires <em>$formid</em> from <b>Form Configuration Datasets</b>):</legend><label for="menu_copyfrmcfg2">Base Upon: <select name="menu_copyfrmcfg2" id="menu_copyfrmcfg2" size="1" style="width: 256px; height: 18px;"><option value="0"><-- MANUAL POPULATION --></option></select></label></fieldset> <br/><fieldset><legend><strong>Field Translations</strong> (Requires <em>$formid</em> from <b>Form Configuration Datasets</b>):</legend><label for="menu_copyfrmcfg3">Base Upon: <select name="menu_copyfrmcfg3" id="menu_copyfrmcfg3" size="1" style="width: 256px; height: 18px;"><option value="0"><-- MANUAL POPULATION --></option></select></label></fieldset> <br/><fieldset><legend><strong>Form Extentions</strong> (Requires <em>$formid</em> from <b>Form Configuration Datasets</b>):</legend><label for="menu_copyfrmcfg4">Base Upon: <select name="menu_copyfrmcfg4" id="menu_copyfrmcfg4" size="1" style="width: 256px; height: 18px;"><option value="0"><-- MANUAL POPULATION --></option></select></label></fieldset> <br/><fieldset><legend><strong>Get Expected Values</strong> (Requires <em>$formid</em> from <b>Form Configuration Datasets</b>):</legend><label for="menu_copyfrmcfg">Base Upon: <select name="menu_copyfrmcfg5" id="menu_copyfrmcfg5" size="1" style="width: 256px; height: 18px;"><option value="0"><-- MANUAL POPULATION --></option></select></label></fieldset> <br/><input name="btn_submit" type="submit" value="Submit" /><input name="btn_reset" type="reset" value="Reset" /></form></body></html> i cannot see how or why the function has stopped working and as result not halting the form submission on error detection anymore. sincerely, Pierre du Toit. 1000.php Edited July 26, 2013 by Pierre 'Greywacke' du Toit Link to comment Share on other sites More sharing options...
justsomeguy Posted July 26, 2013 Share Posted July 26, 2013 Are there any Javascript error messages in the console? Link to comment Share on other sites More sharing options...
Greywacke Posted July 27, 2013 Author Share Posted July 27, 2013 (edited) unfortunately not that clear (submits and reloads the js error log once submitting to the new page and i can hardly read in a splitsecond what displays...) but think i am going to make the function temporarily return with false every time, just to see what is going on, on monday... thanks for the tip justsomeguy ^^ ps: will respond here with results Edited July 27, 2013 by Pierre 'Greywacke' du Toit Link to comment Share on other sites More sharing options...
justsomeguy Posted July 29, 2013 Share Posted July 29, 2013 If you're using Firebug, there is a Persist button on the console to set it to not clear everything on a reload. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now