![]() Topic awaiting preservation: PHP Validation code help (Page 1 of 1) |
|
|---|---|
|
Nervous Wreck (II) Inmate From: |
posted 10-30-2008 21:38
I have a PHP code validating that someone should work but dosent work correctly code: if (isset($_POST['submit'])) {
$errors = array();
//Form Validation
$required_fields = array('forum_name', 'position', 'visible');
foreach($required_fields as $fieldname){
if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != 0)){
$errors[] = $fieldname;
}
}
$fields_with_lengths = array('forum_name' => 225);
foreach($fields_with_lengths as $fieldname => $maxlength ) {
if (strlen(trim(mysql_prep($_POST[$fieldname]))) > $maxlength) { $errors[] = $fieldname; }
}
|
|
Maniac (V) Mad Scientist From: Denver, CO, USA |
posted 10-30-2008 22:39
Well, you could trim that big IF statement down to this: code: if($_POST[$fieldname] == '')
code: $var='';
if(!isset($var)) echo ("This variable is not set");
|
|
Bipolar (III) Inmate From: Minnesota |
posted 10-30-2008 22:41
Change it to $_POST[$fieldname] != "0"; code: echo (int)"";
|
|
Bipolar (III) Inmate From: Minnesota |
posted 10-30-2008 22:44
My code shows why it wasn't working the way you expected. |
|
Nervous Wreck (II) Inmate From: |
posted 10-30-2008 23:08
Thank you very much for your help Nathus this works for me right now as a temporary fix code: if($_POST[$fieldname] == '')
code: if (!isset($_POST[$fieldname]) || (empty($_POST[$fieldname]) && $_POST[$fieldname] != "0"))
|
|
Nervous Wreck (II) Inmate From: |
posted 10-30-2008 23:57
Okay i know im a noob and sound stupid to all you vets lol... |