Really Simple PHP Question

Associate
Joined
2 Nov 2007
Posts
488
Hi,

Im very rusty / new to all this, and just wanted a quick hand. I have a PHP contact form set up and working. I want to add in a "Request callback" with a checkbox. Then if checked, the email will say something like "Call back request? Yes", or if not Call back request? No"

Im struggling with the code. So far ive got:

Code:
// Customer callback?
if ($_POST['checkbox'] == "1") {
echo "checked=\"true\"";
	else {
	echo
$callback = 'Customer requests a call back?'
}

As you can see im not really sure what im doing!

Cheers for any help
 
Associate
OP
Joined
2 Nov 2007
Posts
488
Thanks for the help. I think ive cracked it:

Code:
// Customer callback?
if ($_POST['checkbox'] == "1") {
	$requestCall = 'Yes';
	} else {
	$requestCall = 'No';
	}
		
$callBack = 'Customer requests a call back? <strong>'.$requestCall.'</strong>';

Look any good?
 
Last edited:
Soldato
Joined
27 Dec 2005
Posts
17,042
Location
Bristol
Thanks for the help. I think ive cracked it:

Code:
// Customer callback?
if ($_POST['checkbox'] == "1") {
	$requestCall = 'Yes';
	} else {
	$requestCall = 'No';
	}
		
$callBack = 'Customer requests a call back? <strong>'.$requestCall.'</strong>';

Look any good?

Looks fine, although this is slightly neater/shorter:

Code:
if($_POST['checkbox']) {
$callBack = 'The customer has requested a call back.';
}
echo $callBack;

Just depends if you really want it so "No" if it's null or not.
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,282
Location
Derbyshire
PHP:
if($_POST['checkbox'])
   $callBack = 'The customer has requested a call back.';
echo $callBack;

// or

if($_POST['checkbox']) $callBack = 'The customer has requested a call back.';
echo $callBack;

Shorter again :p.
 
Associate
Joined
11 Jun 2009
Posts
813
Bah! I thought I'd be able to shorten it further using a ternary statement, I come out 3 characters more than Mattus

PHP:
echo ($_POST['checkbox']) ? 'The customer has requested a call back.' : '';
 
Top Bottom