View Full Version : Getting Field Names
01-24-2003, 01:57 PM
firstly writing a form validation class.
Now my problem is i can't get the name of the field that the error has occured in :S so that i can insert it into an associative array and have all the errors that have been found with that field listed with it.
What i want to know is how to i get a field name after the forms been submitted for processing and bound into the super global POST array ? as its really starting to bug me now :S
01-24-2003, 02:47 PM
If the field name is "Fnord" and the form is submitted via POST, you can get at that field with $_POST['Fnord']. Depends a little on the nature of the form field as well... and posting source code could illustrate that for us.
01-24-2003, 04:34 PM
well theres not much code to show you but i think i can offer a better explination.
Right say i have a form input called "name" i know that when i submit this to my processing script i'll have to use it thusly
now i want to use the "name" bit not the variables contents so i can output an array or errors which equate to the fields so i'd want an output like this:
Field : Name - This field is empty please go back and correct
now this data will be pulled from an assciative array.
I'm trying to build a generic class for handling inpur errors all goes well apart from this one bit of functionality
// iterates through and makes $key equal to the form field name and $var equal to the value.
if($var == "")
echo 'FIELD: '.$key.' - invalid as no data';
further ideas --
might need an eval if you are regexing the fieldnames
$reg_email = "email regex";
eval("\$myregex = \$reg_" .$key. ";");
// bad -
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.