Haig Davis wrote:
> alone work fine as does the foreach loop the only issue I have is the IF
> statement comparing $key to expected varieable names.
>
> if($key != ("$customerServiceEmail") || ("$billingEmail") ||
multiple points here..
1: is the key name held in a php variable called $customerServiceEmail?
if you have <input name="customerServiceEmail" /> then use:
<?php
if( $key != 'customerServiceEmail' )
?>
if you have <input name="$customerServiceEmail" /> then use:
<?php
if( $key != '$customerServiceEmail' )
?>
2: if you need to compare multiples then you need to use either..
<?php
if( !in_array( $key , array('customerServiceEmail' , 'billingEmail' ,
'website') ) ) {
?>
<?php
if( $key != 'customerServiceEmail' && $key != 'billingEmail' && $key !=
'website' )
?>
note in the above I've *ass*umed some mistyped logic, in that only
proceed if not ('customerServiceEmail' || 'billingEmail' || 'website') -
which is in correct because string || string || string *always* equals 1
- hence you need the 3 comparisons achieved by using and(&&) or in_array.
3: these two lines override each other, and variable variables aren't
needed here
$$key = $key;
$$key = $value;
here's a full version for you that should work as you expect:
<?php
if( isset($_POST['submit']) ) {
foreach($_POST as $keyTemp => $valueTemp){
$key = mysqlclean($keyTemp);
$value = mysqlclean($valueTemp);
if( in_array( $key , array( 'customerServiceEmail' , 'billingEmail'
) ) ) {
// only email validate if its an email field
if(
preg_match("/^([a-za-z0-9._%...@[a-za-z0-9.-]+\.[a-za-z]{2,4})*$/",
$value) ) {
$style = "yellow";
$formMsg = "Invalid Characters";
$bad = $key;
}
} else if( $key == 'website' ) {
// placeholder incase you want URL validation
} else {
// only gets here if not and email field, and not a website address
if(preg_match("/[^a-zA-Z0-9\s]/", $value)){
$style = "yellow";
$formMsg = "Invalid Characters";
$bad = $key;
}
}
}
}
?>
regards;
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php