Jump to content

Checkbox Fun


tw4n

Recommended Posts

Afternoon all,

 

having yet more fun with php mailer forms so any help would be much appeciated!

 

Currently have a form with a single checkbox to output a simple yes or no answer.

 

As it stand it always outputs no regardless if its ticked or not.

 

Would anyone be able to explain as to why this is?

 

Many thanks, code below!

 

<input name="chktest" type="checkbox" value="on" />

 

<?php 

$myemail = 'xxxxxxxxxxxxxxxxx';//<-----Put Your email address here.

$name = $_POST['name']; 
$number = $_POST['phone']; 
$email = $_POST['email']; 
$pages = $_POST['pages'];
$budget = $_POST['budget'];
$test = $_POST['test']; 

$chktest = ($_POST['chktest']);

if ($chktest=="on") {$chktest="Yes";} else { $chktest="No";}
                

        $to = $myemail; 
        $email_subject = "xxxxxxxx: ".$name;
        $email_body = "You have received a new message. \n \n
        Here are the details:\n \n Name: ".$name." \n \n Number: ".$number." \n \n Email: ".$email." \n \n Pages: ".$pages." \n \n Budget: ".$budget." \n \n chktest: ".$chktest." \n \n  message: \n ".$test; 
        
        $headers = "From: ".$myemail; 
        $headers .= "Reply-To: ".$email_address;
        
        mail($to,$email_subject,$email_body,$headers);
        
        
        
?>

Link to comment
Share on other sites

Moreover, I would argue a radio field is more appropriate for yes/no. Its clearer and having experienced the pain of watching simple minded people use the internet, I think making this sort of thing obvious is a must.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.