I’m trying to call a function that catches variables value on call:
the function:
function check_input_data($INCLUDE_DISABLEDd_types = '', $field1 = '', $field2 = '', $field3 = '', $field4 = '', $field5 = '', $field6 = '', $field7 = '', $field8 = '')
{
if ( !empty( $INCLUDE_DISABLEDd_types ) )
{
global $field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field_1_status, $field_2_status, $field_3_status, $field_4_status, $field_5_status, $field_6_status, $field_7_status, $field_8_status;
if ( $INCLUDE_DISABLEDd_types == 'email_u' )
{
echo "It's noticed the INCLUDE_DISABLEDd var";
if ( !empty( $field1 ) )
{
//I'll tell you what to do later
}
if ( !empty( $field2 ) )
{
echo $field2;
if ( preg_match( "/[^-a-z0-9_]/i", $field2 ) )
{
$field_2_status = true;
$ff = "good input?";
}
else if ( !preg_match( "/[^-a-z0-9_]/i", $field2 ) )
{
$field_2_status = true;
$ff = "bad input?";
}
else
{
$ff= "something is wrong with preg match";
}
echo $ff;
}
}
}
}
Okay so as you can see, the function will look for only 3 different variables(for now). If it finds them, it will do something.
Now here is the call the the function:
check_input_data ('email_u', 'test1', 'LOOK FIELD TWO IS HERE');
Now the first var in the function call is for $included_types the second for $field1 and the third for $field2.
For some reason, the first var ($included_types) which i give a value of email_u is detected but the rest ($field1 and $field2) is not.
The reason i know the first var ($included_types) is detected is because it echo’s out “It’s noticed the included var”.
As you can see, I’ve got an if statement to check if $field2 is empty and if it’s not then i tell it to echo the var. Now it doesn’t execute any code because it thinks $field2 is empty (when its not) so i then change the if statement to do the task if it IS empty and it does it but it echos $field2 with absolutely nothing so i know its not the empty function.
It somehow thinks $field2 is empty.
I’ve also tried giving values for ALL vars:
check_input_data ('email_u', 'test1', 'LOOK FIELD TWO IS HERE', 'test', 'test', 'test', 'test', 'test', 'test');
but it still only picks up the first var, not the rest.
Have I completely mis-understood something? or is there something wrong with the code?
thanks
Remove the global line and it should work.
Generally it is considered bad practice to use global variables at all, You should instead pass them into the function as parameters (as it seems you have already done).