Ninjakreborn Posted November 15, 2006 Share Posted November 15, 2006 I have started using wildteen's, and other people's advice on using array'ed sessions even for temporarily storing vast amounts of data when it deal's with a larger form. I have a form split into 3 sections.the first is small, the other 2 are considerably large. The thing now is that the form's themselves, the fields are getting filled into an array[code]$_SESSION['temp'][/code]That is the master array that contains all the other informationin it then you can access various variables within that array like:[code]$_SESSION['temp']['firstname'];$_SESSION['temp']['lastname'];[/code]The temp session array is where everything is primarily stored.I have 2 smaller array's calledactiontaken and classificationThere are 2 sections of checklists, one will have an array called actiontaken the other will have one called classification, so in the end I will have the $classification['variablename'];and $actiontaken['variablename'];array'sI want to feed them into the bigger session array so there value's can be found like this$_SESSION['temp']['actiontaken']['firstname'];that would access the firstname field informaiton which is in side the array "actiontaken", inside the "temp" array, inside a session.Then also I wuold need access to the variables that were in the original array, like$_SESSION['temp']['variablename'];as well as the one's from the sub-array's when needed, like$_SESSION['temp']['classification']['variablename'];So the point is I need to be able to put smaller array's, inside larger arrays while still having some variables in side that one array.I am afraid if I put the classification and action array, into the session array it might overwrite something??How do I do this properly?say once I collect the data, how do I put it all into the session at once, as a whole? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 15, 2006 Share Posted November 15, 2006 Just do something like this:$_SESSION['temp']['actiontaken'] = $actiontakenThat will now copy the array from $actiontaken in to the newly created temp['actiontakem'] session Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 Ok, so that should put the entire action taken array into the temp array.So for instance if I had first name saved in that 2nd array, after doing that, I could use that by doing[code]<?phpecho $_SESSION['temp']['actiontaken']['firstname'];?>[/code] Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 15, 2006 Share Posted November 15, 2006 Yes. As I said it copies what's in the $actiontaken array into the temp session arrayIts no different to doing this:[code=php:0]$someVar = 'someValue';$sVar = $someVar;echo $sVar // returns the string 'someValue'[/code]Accept you're using an arrary. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 Ok this leaves me with one final question now that I realize that.So if I can get an array called actiontaken with all the variable(value combinations then I am good to goHow do I get them all into an arraydo I have to manually put each field into an arrayor because when I saw people name themsay<input name="actiontaken[]" type="select" value="firstname" /> *just an example*ok, I have a whole bunch of these, which is how I saw to name checkboxes. If I do this, logically it looks like it's going to create an array of the values.I need to be able to access the variables, like $_SESSION['temp']['actiontaken']['firstname'];and it contain I guess, I am not sure how this is going to work out?Edit-See I literally need the action, I don't know.For instance landing,I need to know whether it was selected or not, but in a way I can database it, it's very hard to explain, if someone knows what I mean? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 15, 2006 Share Posted November 15, 2006 You need to do this then:actiontaken[field_name_here] in the name attribute for each form field then, Example:<input name="actiontaken[firstname]" type="text" value="firstname" /> Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 perfect, thanksdo I need to use the['variablename']the ' where they are, or is that not going to be needed since it's still html. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 nevermind I saw your edit, thanks again for the advice. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted November 15, 2006 Share Posted November 15, 2006 When you're naming your fields with associative arrays dont put quotes around your keys otherwise in your PHP code you'll ahve access then like this:array_name['\'key_name\''] or array_name["'key_name'"] it will thing the quotes are part of the html. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 so this would also let me know if it was selected.For instance if I did that in the name's. Then fed them into the session['temp array or whateversay I wanted to check to see if the variable router was selected.I could say for instance if it was selected then the text box below it was required[code]<?phpif (isset($_SESSION['temp']['actiontaken']['router'])) { if (!isset($_POST['textbox'])) { // text box required when selected }else { // not required }}?>[/code]Just an example, could it be used with that type of usage, and be reliable. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 I am running into a few problem's currently, this isn't working the way I need.First I have to get validation down, then I have to get it to prefill back out the one's that were selected.For now, the problem I am currently having isok if you look below you see on post 3, this is where the form itself is, and where I name the array'sthen if you look on post 4 you see where I am attempting to validate the data.At first I thought it was working, but it now doesn't care whether one of the fields of classification are field out or not, that is the first thing, Ihave to test whether one within that array was set.I tried the obvious but it's not reading it right, it doesn't seem to care whether it's set or not, either way it's telling me they didn't check "anything" within classification.THe next thing, is I had it set up, to test the array for the existence of the variable other, and a few other's but this is just an example, if other was selected the field should be required, it's not seeming to read that right either, as it's not even returning to me a message in my error handler when other or another one that I need to validate is checked.These are just 2 of the problem's I am currently having, so it seems like I am not creating, or accessing the array's properly. I think once I get help with this, then I will know then how to access them, and be able to get the rest working.post 3[code]<?php require_once("../master/config/config.php")?><?phpif ($_SESSION['controller'] == true) {?><!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><?php require_once($docroot . "/master/includes/meta.inc.php"); ?><style type="text/css">.labelform3 {text-align:center;}.test {width:600px;}#frontendformdiv3logo {width:600px;}#frontendformdiv3 {width:600px;}</style></head><body id="admin"> <div id="frontendformdiv3logo"><p>Event Incident Accident Report</p></div> <div id="frontendformdiv3"> <p>(*required field)</p> <p><a href="/eventaccident/cleardata.php" title="Clear Data">Clear Data, and return to panel</a> </p> <?phpif ($_GET['get'] != "yes") { if (isset($_POST['submit']) || isset($_GET)) { $errorhandler = ""; $reg = "/^(0[1-9]|1[012])[\\/-](0[1-9]|[12][0-9]|3[01])[ \\/-](19[0-9]{2}|2[0-9]{3})$/"; if ($_POST['eventdate'] == "") { $errorhandler .= "Event Date was left blank.<br />"; } if (isset($_POST['eventdate'])) { if (!preg_match($reg, $_POST['eventdate'])) { $errorhandler .= "Event date was invalid. (mm/dd/yyyy)<br />"; } } if ($_POST['eventtime'] == "") { $errorhandler .= "Event Time was left blank.<br />"; } if (isset($_POST['eventtime'])) { if (!is_numeric($_POST['eventtime'])) { $errorhandler .= "Event time must be number only. Military Time format(0000)<br />"; } } if ($_POST['flightnumber'] == "") { $errorhandler .= "Flight Number was left blank.<br />"; } if ($_POST['scheduleddepartureairport'] == "") { $errorhandler .= "Scheduled Departure Airport was left blank.<br />"; } if ($_POST['scheduledarrivalairport'] == "") { $errorhandler .= "Scheduled Arrival Airport was left blank.<br />"; } if ($_POST['captain'] == "") { $errorhandler .= "Captain was left blank.<br />"; } if ($_POST['pax'] == "") { $errorhandler .= "Pax was left blank.<br />"; } errorhandler($errorhandler); if ($errorhandler != "") { echo "<br />"; $_SESSION['temp']['aircraftnumber'] = stripslashes($_POST['aircraftnumber']); $_SESSION['temp']['eventdate'] = stripslashes($_POST['eventdate']); $_SESSION['temp']['eventtime'] = $_POST['eventtime']; $_SESSION['temp']['flightnumber'] = $_POST['flightnumber']; $_SESSION['temp']['scheduleddepartureairport'] = $_POST['scheduleddepartureairport']; $_SESSION['temp']['scheduledarrivalairport'] = $_POST['scheduledarrivalairport']; $_SESSION['temp']['captain'] = $_POST['captain']; $_SESSION['temp']['firstofficer'] = $_POST['firstofficer']; $_SESSION['temp']['flightattendant'] = $_POST['flightattendant']; $_SESSION['temp']['additionalcrewmembers'] = $_POST['additionalcrewmembers']; $_SESSION['temp']['weather'] = $_POST['weather']; $_SESSION['temp']['flightplan'] = $_POST['flightplan']; $_SESSION['temp']['pax'] = $_POST['pax']; $_SESSION['temp']['lapchildren'] = $_POST['lapchildren']; echo "<p>The link below will allow you to edit the fields. Please note"; echo "That the fields you filled out on the first page where saved, the below link "; echo "only makes you return to the previous page.</p>"; echo "<a href=\"/eventaccident/eventincidentaccidentform2.php?get=yes\" title=\"Return and fix errors\">Return And Fix Errors</a>"; }else { $_SESSION['temp']['aircraftnumber'] = stripslashes($_POST['aircraftnumber']); $_SESSION['temp']['eventdate'] = stripslashes($_POST['eventdate']); $_SESSION['temp']['eventtime'] = $_POST['eventtime']; $_SESSION['temp']['flightnumber'] = $_POST['flightnumber']; $_SESSION['temp']['scheduleddepartureairport'] = $_POST['scheduleddepartureairport']; $_SESSION['temp']['scheduledarrivalairport'] = $_POST['scheduledarrivalairport']; $_SESSION['temp']['captain'] = $_POST['captain']; $_SESSION['temp']['firstofficer'] = $_POST['firstofficer']; $_SESSION['temp']['flightattendant'] = $_POST['flightattendant']; $_SESSION['temp']['additionalcrewmembers'] = $_POST['additionalcrewmembers']; $_SESSION['temp']['weather'] = $_POST['weather']; $_SESSION['temp']['flightplan'] = $_POST['flightplan']; $_SESSION['temp']['pax'] = $_POST['pax']; $_SESSION['temp']['lapchildren'] = $_POST['lapchildren']; $show = true; } }}else {$show = true;} ?> <?php if ($show == true) { ?> <form name="form3" id="form3" action="eventincidentaccidentform4.php" method="post"> <table class="test"> <tr> <td colspan="4" style="text-align:left;"><h2>Action Taken(Select all that apply)</h2></td> </tr> <?php echo "<tr>"; select("actiontaken[abortedtakeoff]", "Aborted Takeoff", "abortedtakeoff"); select("actiontaken[cancelledflight]", "Cancelled Flight", "cancelledflight"); echo "</tr>"; echo "<tr>"; select("actiontaken[declaredemergency]", "Declared Emergency", "declaredemergency"); select("actiontaken[delayedflight]", "Delayed Flight", "delayedflight"); echo "</tr>"; echo "<tr>"; select("actiontaken[diversion]", "Diversion", "diversion"); select("actiontaken[goaround]", "Go Around", "goaround"); echo "</tr>"; echo "<tr>"; select("actiontaken[groundaircraftatoutstation]", "Ground AirCraft At Outstation", "groundaircraftatoutstation"); select("actiontaken[inflightshutdown]", "In Flight Shutdown", "inflightshutdown"); echo "</tr>"; echo "<tr>"; select("actiontaken[missedapproach]", "Missed Approach", "missedapproach"); select("actiontaken[returnaircrafttomaintenance]", "Return Aircraft To Maintenance", "returnaircrafttomaintenance"); echo "</tr>"; echo "<tr>"; select("actiontaken[returntogate]", "Return To Gate", "returntogate"); select("actiontaken[turnback]", "Turn Back", "turnback"); echo "</tr>"; ?> <tr><td colspan="4"><hr /></td></tr> <tr> <td colspan="4" style="text-align:left;"><label for="phaseofflight"><h2>Phase Of Flight:(Select One)</h2></label></td> </tr> <tr> <td colspan="4"><select name="phaseofflight" id="phaseofflight"> <option selected="selected">Please Select One!</option> <option>Fueling</option> <option>Towing</option> <option>Pre Flight</option> <option>Boarding</option> <option>Taxi Out</option> <option>Runup</option> <option>Takeoff</option> <option>Climb</option> <option>Cruise</option> <option>Holding</option> <option>Decent</option> <option>Approach</option> <option>Landing</option> <option>Taxi In</option> <option>Parking</option> <option>Deplanning</option> <option>Post Flight</option> </select></td> </tr> <tr><td colspan="4"><hr /></td></tr> <tr> <td colspan="4" style="text-align:left;"><h2>Classification(Select all that apply)</h2></td> </tr> <?php echo "<tr>"; select("classification[aircraftdamage]", "Aircraft Damage", "aircraftdamage"); select("classification[aircraftonrunway]", "Aircraft On Runway", "aircraftonrunway"); echo "</tr>"; echo "<tr>"; select("classification[aircraftlogsmanualsorphase]", "Aircraft Logs / Manuals / Phase (missing, incomplete, inaccurate)", "aircraftlogsmanualsorphase"); select("classification[airportclosure]", "Airport Closure", "airportclosure"); echo "</tr>"; echo "<tr>"; select("classification[alternatorfailure]", "Alternator Failure", "alternatorfailure"); select("classification[atcdelay]", "ATC Delay", "atcdelay"); echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"><p style=\"padding-bottom:0px; margin-bottom:0px; text-align:left;\"><b>Avionics Failure</b></p></td>"; echo "</tr>"; echo "<tr>"; select("classification[avionicsfailure-communication]", "Communication", "communication"); echo "<td></td>"; echo "<td></td>"; echo "</tr>"; echo "<tr>"; select("classification[avionicsfailure-navigation]", "Navigation", "navigation"); echo "<td></td>"; echo "<td></td>"; echo "</tr>"; echo "<tr><td colspan=\"4\"> </td></tr>"; echo "<tr>"; select("classification[battery]", "Battery", "battery"); select("classification[birdstrike]", "Bird Strike", "birdstrike"); echo "</tr>"; echo "<tr>"; select("classification[brakefailure]", "Brake Failure", "brakefailure"); select("classification[collision]", "Collision (Aircraft Or Object)", "collision"); echo "</tr>"; echo "<tr>"; select("classification[crewincapacitation]", "Crew Incapacitation", "crewincapacitation"); select("classification[debrisonrunway]", "Debris On Runway", "debrisonrunway"); echo "</tr>"; echo "<tr>"; select("classification[deviationofatcinstructions]", "Deviation Of ATC Instructions", "deviationofatcinstructions"); select("classification[distruptiveorsickpassenger]", "Disruptive/Sick Passenger", "disruptiveorsickpassenger"); echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"> </td>"; echo "</tr>"; echo "<tr>"; select("classification[doorwarning]", "Door Warning", "doorwarning"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; text("classification[doorwarningwhichone]", "Which Door?", 200, ""); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"> </td>"; echo "</tr>"; echo "<tr>"; select("classification[dooropening]", "Door Opening", "cdooropening"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; text("classification[dooropeningwhichone]", "Which Door?", 200, ""); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"> </td>"; echo "</tr>"; echo "<tr>"; select("classification[electricalfailure]", "Electrical Failure", "electricalfailure"); select("classification[emergencyevacuation]", "Emergency Evacuation", "emergencyevacuation"); echo "</tr>"; echo "<tr>"; select("classification[enginefailure]", "Engine Failure", "enginefailure"); select("classification[enginefire]", "Engine Fire", "enginefire"); echo "</tr>"; echo "<tr>"; select("classification[fireorsmokeincabin]", "Fire/Smoke In Cabin", "fireorsmokeincabin"); select("classification[flapfailure]", "Flap Failure", "flapfailure"); echo "</tr>"; echo "<tr>"; select("flattire", "Flat Tire", "flattire"); select("flightcontrolfailure", "Flight Control Failure", "flightcontrolfailure"); echo "</tr>"; echo "<tr>"; select("classification[fuelleak]", "Fuel Leak", "fuelleak"); select("classification[fuelquantity]", "Fuel Quantity", "fuelquantity"); echo "</tr>"; echo "<tr>"; select("classification[hardlanding]", "Hard Landing", "hardlanding"); select("classification[icing]", "Icing", "icing"); echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\" style=\"text-align:left;\"><p><b>Instrument Failure?</b></p></td>"; echo "</tr>"; echo "<tr>"; select("classification[flightinstrument]", "Flight Instrument", "flightinstrument"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; text("classification[flightinstrumentwhich]", "Which One?", 200, ""); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[engineinstrument]", "Engine Instrument", "engineinstrument"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; text("classification[engineinstrumentwhich]", "Which One?", 200, ""); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr><td colspan=\"4\"> </td></tr>"; echo "<tr>"; echo "<td><label for=\"landinggear\"><b>Landing Gear</b></label></td>"; echo "<td></td><td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[blowdown]]", "Blow Down", "blowdown"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[failtoextend]]", "Fail To Extend", "failtoextend"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[failtoretract]]", "Fail To Retract", "failtoretract"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[hydraulicleak]]", "Hydraulic Leak", "hydraulicleak"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[hydraulicsystelfailure]]", "Hydraulic System Failure", "hydraulicsystelfailure"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[landinggear[indicationfailure]]", "Indication Failure", "indicationfailure"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"> </td>"; echo "</tr>"; echo "<tr>"; select("classification[lighteningstrike]", "Lightening Strike", "lighteningstrike"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[magnetofailedorrough]", "Magneto (Failed Or Rough):", "magnetofailedorrough"); select("classification[nearmidaircollission]", "Near Mid-Air Collission", "nearmidaircollission"); echo "</tr>"; echo "<tr>"; select("classification[paxinjury]", "Pax Injury", "paxinjury"); select("classification[propstrike", "Prop Strike", "propstrike"); echo "</tr>"; echo "<tr>"; select("classification[roughengine]", "Rough Engine", "roughengine"); select("classification[runwayincursion]", "Runway Incursion", "runwayincursion"); echo "</tr>"; echo "<tr>"; select("classification[starterfailureorwarning]", "Starter (Failure Or Warning)", "failureorwarning"); select("classification[tailstrike]", "Tail Strike", "talestrike"); echo "</tr>"; echo "<tr>"; select("classification[turbulence]", "Turbulence", "turbulence"); select("classification[vacuumfailure]", "Vacuum Failure", "vacuumfailure"); echo "</tr>"; echo "<tr>"; select("classification[waketurbulence]", "Wake Turbulence", "waketurbulence"); select("classification[weatherbelowminimums]", "Weather Below Minimums", "weatherbelowminimums"); echo "</tr>"; echo "<tr>"; select("classification[weatherbelowhighminimums]", "Weather Below High Minimums", "weatherbelowhighminimums"); select("classification[weightandbalance]", "Weight And Balance", "weightandbalance"); echo "</tr>"; echo "<tr>"; select("classification[windshear]", "Wind Shear", "windshear"); echo "<td></td><td></td>"; echo "</tr>"; echo "<tr>"; select("classification[other]", "Other", "cother"); echo "<td colspan=\"2\"></td>"; echo "</tr>"; echo "<tr>"; text("classification[othertext]", "Required(if selected)", 200, ""); echo "<td colspan=\"2\"></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"> </td>"; echo "<tr>"; echo "<td colspan=\"4\"><label for=\"description\">Brief Description:</label></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"><textarea name=\"description\" id=\"description\" cols=\"30\" rows=\"10\"></textarea></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=\"4\"><input name=\"submit\" id=\"submit\" type=\"submit\" value=\"Continue\" /><input name=\"clear\" id=\"clear\" type=\"reset\" value=\"Clear\" /></td>";echo "</tr>"; ?> </table> </form> <?php } ?> </div></body></html><?php}else {header("Location: /index.php");}?>[/code]post 4[code]<?php require_once("../master/config/config.php")?><?phpif ($_SESSION['controller'] == true) {?><!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><?php require_once($docroot . "/master/includes/meta.inc.php"); ?><style type="text/css">.labelform3 {text-align:center;}.test {width:600px;}#frontendformdiv3logo {width:600px;}#frontendformdiv3 {width:600px;}</style></head><body id="admin"> <div id="frontendformdiv3logo"><p>Event Incident Accident Report</p></div> <div id="frontendformdiv3"> <p>(*required field)</p> <p><a href="/eventaccident/cleardata.php" title="Clear Data">Clear Data, and return to panel</a> </p> <?php if (isset($_POST['submit']) || isset($_GET)) { $errorhandler = ""; if (!is_array($_POST['classification'])) { $errorhandler .= "You have to check atleast one of the classifications.<br />"; } if (isset($_POST['classification[doorwarning]'])) { if ($_POST['classification[doorwarningwhichone]'] == "") { $errorhandler .= "If Door Warning is selected, the text box must also<br />"; $errorhandler .= "be filled in.<br />"; } } if (isset($_POST['classification[dooropening]'])) { if ($_POST['classification[dooropeningwhichone]'] == "") { $errorhandler .= "If Door Opening is selected, the text box must also<br />"; $errorhandler .= "be filled in.<br />"; } } if (isset($_POST['classification[flightinstrument]'])) { if ($_POST['classification[flightinstrumentwhich]'] == "") { $errorhandler .= "If Door Opening is selected, the text box must also<br />"; $errorhandler .= "be filled in.<br />"; } } if (isset($_POST['classification[engineinstrument]'])) { if ($_POST['classification[engineinstrumentwhich]'] == "") { $errorhandler .= "If Door Opening is selected, the text box must also<br />"; $errorhandler .= "be filled in.<br />"; } } if (isset($_POST['classification[other]'])) { if ($_POST['classification[othertext]'] == "") { $errorhandler .= "If Door Opening is selected, the text box must also<br />"; $errorhandler .= "be filled in.<br />"; } } if ($_POST['description'] == "") { $errorhandler .= "The description was left blank, it has to be filled in.<br />"; } errorhandler($errorhandler); if ($errorhandler != "") { echo "<br />"; // session variables here echo "<p>The link below will allow you to edit the fields. Please note"; echo "That the fields you filled out on the first page where saved, the below link "; echo "only makes you return to the previous page.</p>"; echo "<a href=\"/eventaccident/eventincidentaccidentform3.php?get=yes\" title=\"Return and fix errors\">Return And Fix Errors</a>"; }else { // session variables here $show = true; } } ?> <?php if ($show == true) { ?> <p>This is where all the information itself is going to go, like the actual confirmation message or something.</p> <?php } ?> </div></body></html><?php}else {header("Location: /index.php");}?>[/code]edit - Also yes, I know I used tables to layout the form, I got tired this time of fighting with the css, this time, it was murder. So I did the form itself in tables, in a css layout.I may start doing all my advanced form's like that, this one took me 2 day's to layout because of how big it was, it was split up into 3-4 parts. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 anybody? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 Ok, by some wierd chance, I learnt how to check the array's, to make sure if they were set, then the proper text field had to be set as well, I also learnt a valuable new skill for later projects.However I can't figure out how to test the classifications arrayin general to see if any were filled inThe only requirement right now, is that atleast 1 of them is filled out, I have tried the following code's and nothing has worked.[code]if (!$_POST['classification']) { $errorhandler .= "You have to check atleast one of the classifications.<br />";}[/code][code]if (!is_array($_POST['classification'])) { $errorhandler .= "You have to check atleast one of the classifications.<br />";}[/code][code]if (!isset($_POST['classification'])) { $errorhandler .= "You have to check atleast one of the classifications.<br />";}[/code]if ($_POST['classification'] == "") { $errorhandler .= "You have to check atleast one of the classifications.<br />";}None of this stuff is working, I went on to try 4-5 other variations but nothing is seeming to work properly, I don't understand it, any advice would be appreciated. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 15, 2006 Author Share Posted November 15, 2006 I would be eternally grateful is someone knew:D Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 15, 2006 Share Posted November 15, 2006 If it's an array, use count(); Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 16, 2006 Author Share Posted November 16, 2006 I recently tried that, no luck, I tried counting it in the variable, I tried testing to see if it was 0, and if it was return an error, I don't know, nothing is working.I just need to check the array, see if any check boxes under that array where checked, that's it, any advice? Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 16, 2006 Author Share Posted November 16, 2006 Well I echo'd out the count variable and it returned 5so for some reason the default was 5, I guess the sub arrays I fed the array, counted out numbers even though no variables were set to thoseso [code]<?php$n = count($_POST['classification']);if ($n == 5) { $errorhandler .= "You have to check atleast one of the classifications.<br />";}?>[/code]Seemed to work, I tested it a few time's and it seem's to function is this going to be reliable int he future as well. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 16, 2006 Share Posted November 16, 2006 [code]<?php // test.php // Display a form that uses checkboxes as an array // Validate that at least one selection was made if(count($_POST)){ echo "<pre>" . print_r($_POST, true) . "</pre>"; // Form was submitted if(is_array($_POST['checks']) && count($_POST['checks'])){ foreach($_POST['checks'] as $check){ echo "You selected: {$check}<br />"; } }else{ echo "You did not make any selections!<br />"; } }else{ // Displaying form $form = <<<THEFORM <form name="theform" method="post" action=""> <input type="checkbox" name="checks[]" value="opt1" />Option 1<br/> <input type="checkbox" name="checks[]" value="opt2" />Option 2<br/> <input type="checkbox" name="checks[]" value="opt3" />Option 2<br/> <input type="checkbox" name="checks[]" value="opt4" />Option 2<br/> <input type="submit" name="submit" value="Submit" /> </form>THEFORM; echo $form; }?>[/code]count() doesn't default to anything, it counts the number of elements in an array and that's it. Picking an arbitrary number, such as 5, and calling that ground zero is not necessarily reliable. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 16, 2006 Author Share Posted November 16, 2006 yes but when I natuarlly counted the variables. And simply outputed what the count variable held,without me checking any checkbox's, it started at 5.So I ended up havnig to use that, it automatically set the number to 5 Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 16, 2006 Share Posted November 16, 2006 Place this code somewhere in the area where the form is being processed:[code]<?phpecho '<pre style="text-align: left;">' . print_r($_POST, true) . '</pre>';?>[/code]Then submit the form without checking any of the boxes and paste the contents of the $_POST array here. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 20, 2006 Author Share Posted November 20, 2006 [code]Array( [phaseofflight] => none [classification] => Array ( [doorwarningwhichone] => [dooropeningwhichone] => [flightinstrumentwhich] => [engineinstrumentwhich] => [othertext] => ) [description] => [submit] => continue)[/code]This is what is outputted. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 20, 2006 Share Posted November 20, 2006 Here is the relevant piece of information:[code]Array( [classification] => Array ( [doorwarningwhichone] => [dooropeningwhichone] => [flightinstrumentwhich] => [engineinstrumentwhich] => [othertext] => ))[/code]Now do the same exact thing, but this time check one of the boxes associated with one of the following values:doorwarningwhichone, dooropeningwhichone, flightinstrumentwhich, engineinstrumentwhich, othertextI can almost garauntee your form validation will fail and tell you that you must check at least one box for the classification. If you didn't check any boxes, none of those keys should exist inside [i]classification[/i]. They do for some reason and I'm not gonna pick apart your code to find out why. But it just doesn't seem right to me. 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.