turpentyne Posted March 29, 2012 Share Posted March 29, 2012 I'm completely stumped on this one. I'm posting the whole page of script, because I just can't see why this form wouldn't call the validation script. <?php /* set the cache limiter to 'private' */ session_cache_limiter('private'); $cache_limiter = session_cache_limiter(); /* set the cache expire to 7 minutes */ session_cache_expire(7); $cache_expire = session_cache_expire(); /* start the session */ session_start(); $_SESSION['page'] = 1; if ($_SESSION['page'] != 1) { header("Location: register.php"); exit; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type='text/javascript'> function validation1(){ alert("sometext"); // Make quick references to our fields // doesnt even make it this far { // Make quick references to our field *ARRAYS*: var fname = document.register1["kfname[]"]; var lname = document.register1["klname[]"]; var birth_month = document.register1["bdate2[]"]; var birthday = document.register1["bdate[]"]; var birthyear = document.register1["bdate3[]"]; for ( var f = 0; f < fname.length; ++f ) { var n = f+1; if( ! isAlphabet(fname[f], "Please enter only letters for first name " +n) || ! isAlphabet(lname[f], "Please enter only letters for last name " +n) || ! madeSelection(birth_month[f], "Pleace choose a birth month for name " +n) || ! madeSelection(birthday[f], "Please choose a birth day for name " +n) || ! madeSelection(birthyear[f], "Please choose a birth year for name " +n) ) { return false; } } return true; } function isAlphabet(elem, helperMsg){ var alphaExp = /^[a-zA-Z ]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function isAlphanumeric(elem, helperMsg){ var alphaExp = /^[0-9a-zA-Z\s]+$/; if(elem.value.match(alphaExp)){ return true; }else{ alert(helperMsg); elem.focus(); return false; } } function madeSelection(elem, helperMsg){ if(elem.value == ''){ alert(helperMsg); elem.focus(); return false; }else{ return true; } } </script> </head> <div id="container"> <? include("header.php"); ?> <div id="div_name" style="visibility:hidden;solid #aaa; z-index:5000;height:0px;position:relative;top:-96px;left:-55px;"><div style="background-color:#ffffff;width:100px;z-index:5001;padding:9px;-moz-border-radius: 17px; -webkit-border-radius: 17;border-radius: 17px;"> Hi! I'm ORHO! <br>Find out more about me here...</div> </div> <p><!-- start central content area --> <img src="images/head/head_reg2.gif" style="position:relative;left:-43px;top:5px;"/><br> <?php if (isset($_POST["submit"])) { if ($_POST["unique_id_form"] == $_SESSION["unique_id"]) { $_SESSION["unique_id"] = ''; } else echo 'error'; } else { $_SESSION["unique_id"] = uniqid (rand (),true); } if ( (isset($_POST['fname'])) && ($_POST['fname'] !='') && (isset($_POST['email'])) && ($_POST['email'] !='') && (isset($_POST['phone'])) && ($_POST['phone'] !='') ){ function isValidEmail($email){ return eregi('^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$', $email); } if (isset($_POST['participantqty']) && max($_POST['participantqty']) > 0){ // connect to database include("Dbconn.php"); $_SESSION['s_fname'] = mysql_escape_string($_POST['fname']); $_SESSION['s_lname'] = mysql_escape_string($_POST['lname']); $_SESSION['s_address1'] = mysql_escape_string($_POST['address1']); $_SESSION['s_address2'] = mysql_escape_string($_POST['address2']); $_SESSION['s_city'] = mysql_escape_string($_POST['city']); $_SESSION['s_state'] = mysql_escape_string($_POST['state']); $_SESSION['s_zip'] = mysql_escape_string($_POST['zip']); $_SESSION['s_phone'] = mysql_escape_string($_POST['phone']); $_SESSION['s_fax'] = mysql_escape_string($_POST['fax']); $_SESSION['s_email'] = mysql_escape_string($_POST['email']); /*$_SESSION['s_hear'] = mysql_escape_string($_POST['hear']); $_SESSION['s_how1'] = mysql_escape_string($_POST['how1']); $_SESSION['s_how2'] = mysql_escape_string($_POST['how2']); $_SESSION['s_how3'] = mysql_escape_string($_POST['how3']); $_SESSION['s_how4'] = mysql_escape_string($_POST['how4']); */ $_SESSION['s_resident'] = mysql_escape_string($_POST['resident']); $_SESSION['s_phone2'] = mysql_escape_string($_POST['phone2']); } } $filtered = array_filter($_POST['participantqty']); $_SESSION['s_participantqty'] = array_filter($_POST['participantqty']); echo "<br><p style='font-size:1.25em;color:#f67026;padding-bottom:10px;'>Enter the name(s) that you want to enroll in each class</p></b><br>"; // start the form generation based on class selection from previous page foreach($filtered as $key => $line) { $query_class = "SELECT workshop_title FROM tbl_workshops WHERE workshop_id = $key"; //$result_class = mysql_query($query_class); $r = mysql_query($query_class) or die(mysql_error()); //$g_row = mysql_fetch_array($query_class); while($row = mysql_fetch_array($r)) { echo "<p style='font-size:1.25em;color:#000;padding-bottom:10px;'><span style='font-size:.9em;color:#7E3F0F;'>ENROLLEES FOR: </span>".$row['workshop_title']."</p>";} $count = $line; $i = 1; while ($i <= $count) { $i++; /* the printed value would be $i before the increment (post-increment) */ $x = $i-1; ?><form name="register1" class="registration_form" method="post" action="register2.php" target="_self" onsubmit="return validation1()"> <b><?= $reg_id ?><span style='color:#777777;padding-bottom:10px;'> Child #<?= $x ?> </span></b> <img src="/images/greenblack.gif" style="height:2px; width:450px;position:relative;left:5px;top:-3px;"><br><br> <div style="float:left; padding-right:20px;">Kid's First Name<br><input type="text" name="kfname[]" id="fname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /></div> <div style="float:left; padding-right:20px;">Kid's Last Name<br><input type="text" name="klname[]" id="lname" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" /></div> <div>Birthdate<br><div style=""> <select style="width:75px;" id="birth_month" name="bdate2[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">month</option> <option value="01">Jan</option> <option value="02">Feb</option> <option value="03">Mar</option> <option value="04">Apr</option> <option value="05">May</option> <option value="06">Jun</option> <option value="07">Jul</option> <option value="08">Aug</option> <option value="09">Sept</option> <option value="10">Oct</option> <option value="11">Nov</option> <option value="12">Dec</option> </select> <select style="width:57px;" id="birthday" name="bdate[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">day</option> <option value="01">01</option> <option value="02">02</option> <option value="03">03</option> <option value="04">04</option> <option value="05">05</option> <option value="06">06</option> <option value="07">07</option> <option value="08">08</option> <option value="09">09</option> <option value="10">10</option> <option value="11">11</option> <option value="12">12</option> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="26">26</option> <option value="27">27</option> <option value="28">28</option> <option value="29">29</option> <option value="30">30</option> <option value="31">31</option> </select> <select style="width:60px;" id="birthyear" name="bdate3[]" onfocus="this.className='reg_live';" onblur="this.className='reg_off';" > <option value="">year</option> <option value="1993">1993</option> <option value="1994">1994</option> <option value="1995">1995</option> <option value="1996">1996</option> <option value="1997">1997</option> <option value="1998">1998</option> <option value="1999">1999</option> <option value="2000">2000</option> <option value="2001">2001</option> <option value="2002">2002</option> <option value="2003">2003</option> <option value="2004">2004</option> <option value="2005">2005</option> <option value="2006">2006</option> <option value="2007">2007</option> <option value="2008">2008</option> <!--<option value="2009">2009</option> <option value="2010">2010</option> <option value="2012">2012</option> <option value="2013">2013</option> <option value="2014">2014</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> <option value="2018">2019</option> <option value="2018">2020</option>--> </select></div></div> <br> <input type="hidden" name="workshop_id[]" id="workshop_id" value="<?php echo $key; ?>"> </td></tr></table><br><br> <?php } } ?><br /> <input type="submit" value="next" /> </form> <!-- end central content area --> <br /><br /><br /><br /> </div> </p></div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/ Share on other sites More sharing options...
smerny Posted March 29, 2012 Share Posted March 29, 2012 php is server side and only executes on page load, you're trying to access it like it's javascript... onsubmit calls javascript if you want to have real time (before the next page loads) validation you'll need to do it with javascript. Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332455 Share on other sites More sharing options...
turpentyne Posted March 29, 2012 Author Share Posted March 29, 2012 Forgive me, I don't think I explained properly. the php is just generating a looped series of forms. On the completed page, clientside, I have the javascript at top verifying the form fields before they continue onto the next page. This is what's not working - not related to php issues. So, this prints to the page, but doesn't seem to get to the javascript: <form name="register1" class="registration_form" method="post" action="register2.php" target="_self" onsubmit="return validation1()"> onsubmit="return validation1()" calls the javascript before it sends to the next php location. But it doesn't seem to be working. Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332501 Share on other sites More sharing options...
smerny Posted March 29, 2012 Share Posted March 29, 2012 ah, somehow i missed that... not even sure how, mind must have been on something else. my bad. have you ran with firebug or some kind of developer console open? Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332504 Share on other sites More sharing options...
smerny Posted March 29, 2012 Share Posted March 29, 2012 i just threw it in my text editor real quick and noticed this: function validation1(){ alert("sometext"); // Make quick references to our fields // doesnt even make it this far { // Make quick references to our field *ARRAYS*: ..... for ( var f = 0; f < fname.length; ++f ) { var n = f+1; if( ! isAlphabet(fname[f], "Please enter only letters for first name " +n) || ! isAlphabet(lname[f], "Please enter only letters for last name " +n) || ! madeSelection(birth_month[f], "Pleace choose a birth month for name " +n) || ! madeSelection(birthday[f], "Please choose a birth day for name " +n) || ! madeSelection(birthyear[f], "Please choose a birth year for name " +n) ) { return false; } } return true; } there's one extra open bracket Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332505 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2012 Share Posted March 29, 2012 Also, your HTML is far from being valid. The opening <form > tag is inside your looping code, so you will be producing multiple opening <form > tags, but your closing </form> tag (one of them) is after the end of the loops. Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332510 Share on other sites More sharing options...
turpentyne Posted March 29, 2012 Author Share Posted March 29, 2012 yay! and boo. I didn't even notice those two issues. Moved the <form... > outside of the loop, and got rid of the extra brackets. But still no good. Then I went through firebug's console to see what errors I get. Nada. grrr.. Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332526 Share on other sites More sharing options...
turpentyne Posted March 30, 2012 Author Share Posted March 30, 2012 AHA! fixed. I changed the variable setting to: var fname = document.getElementsByName("kfname[]"); var lname = document.getElementsByName("klname[]"); var birth_month = document.getElementsByName("bdate2[]"); var birthday = document.getElementsByName("bdate[]"); var birthyear = document.getElementsByName("bdate3[]"); works like a charm. Quote Link to comment https://forums.phpfreaks.com/topic/259963-form-not-calling-validation-script/#findComment-1332531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.