Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, Everybody
This is the kind of problem I faced when I was checking for the error messages. This is the codeCode: Select all
//Validation of fields entered if js is dsabled
$error_msg = array();
if(($str = $val[0]) || ($str = $val[1]))
{
$error_msg[] = (validate::name($str)) ? NULL : 'Enter the Name field properly';
}
else
{
$error_msg[] = 'First name or last name cannot be empty';
}
if($val[2])
{
$error_msg[] = (validate::name($val[2])) ? NULL : 'Enter the Address field properly';
}
if($val[3])
{
$error_msg[] = (validate::name($val[3])) ? NULL : 'Enter the City field properly';
}
if($val[4])
{
$error_msg[] = (validate::name($val[4])) ? NULL :'Enter the State properly';
}
if($val[5])
{
$error_msg[] = (validate::number($val[5])) ? NULL : 'Enter the Zip code properly';
}
if($val[7])
{
$error_msg[] = (validate::number($val[7])) ? NULL : 'Enter the Telephone number properly';
}
else
{
$error_msg[] = 'Telephone number field cannot be empty';
}
//print("<pre>");print_r($error_msg);die();
if(count($error_msg)>0)
{
$error_str = implode('.', $error_msg);
print($error_str);
}
//end of validationIn this expression, (exp1) ? NULL : (error display string);, If there are some errors then the validation functions return false and , the value returned to array is err string else NULL is returned, Finally at last I am checking whether the array size is greater than one then display the error string.
But even though , there is no input with errors, still the array contains elements all initialized to NULL, Hence enters the final if condition with displaying a null condition, Which I was not expecting to happen..........., Finally solved this by having below code
Can any one explain, How can we avoid this null assignment...what could be the reason
twigletmac | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]