compare form fields before email

mcornell 10 Feb, 2011
I am trying to test if one of four check boxes is marked as follows:


if (JRequest::getVar('chkwater')=Yes) ||JRequest::getVar('chkfire')=Yes) ||JRequest::getVar('chkpolice')=Yes) ||JRequest::getVar('chkotheremergency')=Yes) {

// If it is emergency we will send a text message

mail($maintemail, 'EMERGENCY', $emailmessage, $headers);

}
the field name="chkwater" and so on for the rest

as per the rest of my script i get the email for records but i do not get text message (via email)

this works in a standalone script without the if clause.

Any suggestions?
GreyHead 10 Feb, 2011
Hi mcornell ,

You can't use JRequest inside an if statement (usually this shows a PHP error); and the syntax of your 'if' comparisons is buggy.
<?php
$water = JRequest::getString('chkwater', '', 'post');
$fire = JRequest::getString('chkfire', '', 'post');
$police = JRequest::getString('chkpolice', '', 'post');
$other = JRequest::getString('chkotheremergency', '', 'post');
if ( $water == 'yes' || $fire == 'yes' || $police == 'yes' || $other == 'yes' ) {
  // If it is emergency we will send a text message
  mail($maintemail, 'EMERGENCY', $emailmessage, $headers);
}
?>

Bob



Bob
This topic is locked and no more replies can be posted.