Skipjackrick Posted March 28, 2008 Share Posted March 28, 2008 I recently added a required fields form validation code and now my form won't submit. Can anybody check to see if I am missing something? HTML HEAD <script language="JavaScript"> <!-- /*********************************************** * Required fields validation ***********************************************/ function formCheck(formobj){ // Enter name of mandatory fields var fieldRequired = Array("team_id", "species_id", "mm", "dd"); // Enter field description to appear in the dialog box var fieldDescription = Array("Team Name", "Species Name", "Month", "Day"); // dialog message var alertMsg = "Please complete the following fields:\n"; var l_Msg = alertMsg.length; for (var i = 0; i < fieldRequired.length; i++){ var obj = formobj.elements[fieldRequired[i]]; if (obj){ switch(obj.type){ case "select-one": if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "select-multiple": if (obj.selectedIndex == -1){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; case "text": case "textarea": if (obj.value == "" || obj.value == null){ alertMsg += " - " + fieldDescription[i] + "\n"; } break; default: } if (obj.type == undefined){ var blnchecked = false; for (var j = 0; j < obj.length; j++){ if (obj[j].checked){ blnchecked = true; } } if (!blnchecked){ alertMsg += " - " + fieldDescription[i] + "\n"; } } } } if (alertMsg.length == l_Msg){ return true; }else{ alert(alertMsg); return false; } } // --> </script> HTML BODY <?php if (isset($_POST['Submit'])) { $team_id = $_POST['team_id']; $angler = $_POST['angler']; $species_id = $_POST['species_id']; $points = $_POST['points']; $length = $_POST['length']; $yyyy = $_POST['yyyy']; $mm = $_POST['mm']; $dd = $_POST['dd']; $image = $_POST['image']; $region_id = $_POST['region_id']; # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(submit_id, team_id, angler, species_id, points, length, yyyy, mm, dd, image, region_id) values ('$submit_id', '$team_id', '$angler', '$species_id', '$points', '$length', '$yyyy', '$mm', '$dd', '$image', '$region_id')"; if($result = mysql_query($sql ,$db)) { echo "<br>"; echo "Thank you, Your information has been entered into the database."; echo "<br>"; echo "<br>"; echo "<a href='http://www.extremecoast.com/Kayak_Wars/Rockstar/upload.form.php'>"; echo "Click here to make another submission"; echo "</a>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<br>"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <form action="" enctype="multipart/form-data" name="form" id="form" onsubmit="return formCheck(this);" > <input type="hidden" name="submit_id" value="NULL"> <input type="hidden" name="region_id" value="1"> <tr> </tr><div align="center"></div><tr><td><div align="left" class="style2"></div></td> <td><label></label></td> </tr><tr><td> </td> </tr> <tr> <td> </td> <td><label></label></td> </tr> <tr> <td colspan="2"><div align="center"> <label></label> <label></label> <table width="600" border="0"> <tr> <td width="66" rowspan="5"> </td> <td width="168"><span class="style2 style1">Team</span></td> <td width="300"><select name="team_id" id="team_id" onChange="teamChange(this);"> <option value="0">Select a Team</option> <option value="1">Rockstar</option> <option value="2">Plastic Pirates</option> <option value="3">Lone Star Sharkers</option> <option value="4">Roadrunner</option> <option value="5">Hawg Wild</option> <option value="6">Mojo</option> <option value="7">TAMUK Anglers</option> <option value="8">Krakatoa</option> <option value="9">Why Knot</option> <option value="10">Kraken</option> </select></td> <td width="66" rowspan="5"> </td> </tr> <tr> <td><span class="style1">Angler</span></td> <td><select name="angler" id="angler"> <option value="0">Select Angler</option> </select></td> </tr> <tr> <td><span class="style1">Species</span></td> <td><select name="species_id" id="species_id" onChange="calc_points();"> <option value="0">Select Species</option> <option value="1">Red Drum</option> <option value="2">Trout</option> <option value="3">Snook</option> <option value="4">Shark</option> <option value="5">Black Drum</option> <option value="6">Snapper</option> <option value="7">King Mackerel</option> <option value="8">Grouper</option> <option value="9">Cobia (Ling)</option> <option value="10">Flounder</option> <option value="11">Tarpon</option> <option value="12">Tripletail</option> <option value="13">Permit</option> <option value="14">Blackfin Tuna</option> <option value="15">Yellowfin Tuna</option> <option value="16">Barracuda</option> <option value="17">Bonefish</option> <option value="18">Dorado</option> <option value="19">Wahoo</option> <option value="20">Billfish</option> <option value="21">Amberjack</option> </select> <span class="style1">Points</span> <input name="points2" type="text" id="points2" size="5" maxlength="4"><input name="points" type="hidden" id="points" size="5" maxlength="4"></td> </tr> <tr> <td><span class="style1">Enter Length (inches)</span></td> <td><input name="length" type="text" id="length" size="4" maxlength="5"> <span class="style1">Estimate if unknown</span></td> </tr> <tr> <td><span class="style1">Date of Catch</span></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">9</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></td> </tr> <tr> <td height="68" colspan="4"> <div align="center"> <input type="Submit" name="Submit" class="button" id="Submit" value="Submit"> </div></td> </tr> </table> </div></td> </tr> <?php $query_image2 = "SELECT image_id, filename, team_id, date FROM image WHERE team_id=1 ORDER BY image_id DESC LIMIT 1"; $image_result2 = mysql_query($query_image2) or die(mysql_error()); while($row = mysql_fetch_array($image_result2)) { $imagename = $row['filename']; $display_image2 .=<<<EOD <input type="hidden" name="image" value="http://www.extremecoast.com/Kayak_Wars/Rockstar/uploaded_files/$imagename"> EOD; } print $display_image2; ?> </form> <?php $query_image = "SELECT image_id, filename, team_id, date FROM image WHERE team_id=1 ORDER BY image_id DESC LIMIT 1"; $image_result = mysql_query($query_image) or die(mysql_error()); while($row = mysql_fetch_array($image_result)) { $imagename = $row['filename']; $display_image .=<<<EOD <h2><div align="center"><img src="http://www.extremecoast.com/Kayak_Wars/Rockstar/uploaded_files/show_image.php?filename=$imagename&width=400&height=400"></div></h2> EOD; } echo "If this is not the image you intended to upload."; echo "<br>"; echo "<a href='http://www.extremecoast.com/Kayak_Wars/Rockstar/upload.form.php'>"; echo "Click here to change your image."; echo "</a>"; print $display_image; ?> <?php } ?> Quote Link to comment Share on other sites More sharing options...
Skipjackrick Posted March 28, 2008 Author Share Posted March 28, 2008 I figured it out. I forgot method="POST" In the form field Quote Link to comment 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.