Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Fun with checkboxes

Featured Replies

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" />

 

<?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 = "Freelance Query: ".$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);



?>

  • Author

You need to give your checkbox a value attribute.

 

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

 

Thanks for the quick reply, I just assumed that on was a default value for the checkbox being ticked.

 

Unfortunately this still hasn't fixed the problem.

 

Looked through various threads already but its just been a bit of a cut and paste job and haven't had any working results yet.

You need to examine your HTTP post data, something in there is probably not whats expected. Use firebug or print_r($_POST) in your code.

  • Author

Thanks for your help Jock.

 

I stripped back the php file to just include the form and nothing else and it worked perfectly.

 

Adding the rest of the pages in bit by bit I narrowed the problem down to the validation script.

 

the JavaScript validation file that I am using does not effect the check box or two drop down boxes that I am using, but when implemented it stops the drop down box values from being mailed and always returns no for the check box value.

 

Has anyone experienced this before?

 

Thanks.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.