Jump to content

Problem reading array's, validation's not working.


Ninjakreborn

Recommended Posts

  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 information
in 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 called
actiontaken and classification
There 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's
I 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?
Link to comment
Share on other sites

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 go
How do I get them all into an array
do I have to manually put each field into an array
or because when I saw people name them
say
<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?
Link to comment
Share on other sites

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 whatever
say 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]<?php
if (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.
Link to comment
Share on other sites

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 is
ok if you look below you see on post 3, this is where the form itself is, and where I name the array's
then 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")?>
<?php
if ($_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 ($_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\">&nbsp;</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\">&nbsp;</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\">&nbsp;</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\">&nbsp;</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\">&nbsp;</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\">&nbsp;</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\">&nbsp;</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")?>
<?php
if ($_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.
Link to comment
Share on other sites

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 array
in general to see if any were filled in
The 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.
Link to comment
Share on other sites

Well I echo'd out the count variable and it returned 5
so 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 those
so
[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.
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

Place this code somewhere in the area where the form is being processed:
[code]<?php
echo '<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.
Link to comment
Share on other sites


[code]Array
(
    [phaseofflight] => none
    [classification] => Array
        (
            [doorwarningwhichone] =>
            [dooropeningwhichone] =>
            [flightinstrumentwhich] =>
            [engineinstrumentwhich] =>
            [othertext] =>
        )

    [description] =>
    [submit] => continue
)
[/code]

This is what is outputted.
Link to comment
Share on other sites

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, othertext

I 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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.