How can I setup an array, that one could type form field names into - then I would need run through that array to make sure each field listed (in the array) is not empty.
I know how to make arrays, and I know how to check if a field is empty. But I am having trouble combining the two.
Just a guess becuase I had those troubles in the past too, but is it becuase your not naming your input fields properly?
Correct: <input type="text" name="field_name[]">
Incorrect <input type="text" name="field_name">
What exactly are you running into that is causing the problem?
I have not even tried because I don't know where to begin. I want something like:
array($fieldname, $fieldname2, $fieldname3);
then something that compares each field name in the array to:
if(empty($array[1])) { echo"error";}
etc...
<?php if(isset($_POST['submit'])){ $info = $_POST['info']; $name = $info[0]; $zip = $info[1]; if(empty($name) || empty($zip)){ echo "Error"; exit(); } echo "Hello ".$name.". You entered zip code: ".$zip; } else { echo "<form action=\"$PHP_SELF\" methoer=\"POST\">"; //these lines will assign each value a number starting with 0 echo "Name:<input type=\"text\" name=\"info[]\"><br> Zip Code:<input type=\"text\" name=\"info[]\"><br> <input type=\"submit\" name=\"submit\"></form>"; }
I don't think it's clear what I want to do.
I want a function to check if ANY field on a form is empty, but the way that it obtains the field names should come from an array that a user could modify.
Say the user opens the php file, and adds ten field names to the array. I just need a function to run through ANY and ALL fields named in the array and check to see if they're empty.
$array = $_POST['array']; $cnt = count($array); $start=0; while($start<$cnt){ if(empty($array[$start])){ echo "Error, one field empty!"; } else { echo "Field ok!"; } $start++; }
That probably wont do you any good for use, but it should give you an idea how to check if it is empty or not and what to do if it is or not.