Results 1 to 2 of 2
Thread: How Can I Do This?
-
09-17-2002, 09:56 PM #1Junior Guru
- Join Date
- Oct 2001
- Posts
- 193
How Can I Do This?
I added an error checking section in my form script and I was wondering if somone can help me out. Instead of doing this:
PHP Code:// define fields
$fields = array ('field1', 'field2', 'field3');
// print the error
if (empty($_POST['fields'])) {
$field1_error='Error';
$field2_error='Error';
$field3_error='Error';
etc.
etc.
SOMETHING_error='Error'
This way I won't have to make another line for each field.
Any help would be greatly appreciated.
Thanks,
JTM
-
09-20-2002, 02:34 AM #2Newbie
- Join Date
- May 2002
- Posts
- 6
did a little searching on php.net
so to do what you want would be
PHP Code:foreach ($HTTP_POST_VARS AS $pram=>$value){
define ($value . "_error", "Error Text");
}
Ben
so...
if (empty($_POST['fields'])) {
$fields = $_POST['fields'];
for($i=0;$i<count($fields);i++){
define ($fields[$i] . "_error", "Error Text");
};
//All done
};
to test the values....(you can also use the for next here as well
if ( defined('something_error') && something_error ) print(something_error);
you may also use a case insensative feature by inserting
, TRUE);
at the end of
define ($fields[$i] . "_error", "Error Text", TRUE);Last edited by turnball; 09-20-2002 at 02:47 AM.