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.

Checkbox value when emailed

Featured Replies

Hi,

 

I have created an online form with a series of check boxes. When a client submits the form an email is received with all details. However, all the check boxes have a value of 'On'.

 

Can I change this to 'Yes' somehow?

 

Many thanks! :D

  • Author

Legend! Thank you!! Where should I put it in the following code?

 

<?php

$my_email = "info@example.com";

$from_email = "Example Company";

$continue = "thank_you.html";

$errors = array();

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = stripslashes($message);

$subject = "New Order Form Enquiry";

$subject = stripslashes($subject);

if($from_email)
{

$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];

}
else
{

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}

$headers = "From: {$from_name} <{$_REQUEST['email']}>";

}

mail($my_email,$subject,$message,$headers);

?>

  • Author

Right at the top of the script. can I ask where you learnt to use code like that as it is massively outdated

 

It was a free online form that I've used for years. It's just the one I'm used to using I guess!! Thank you for your help mate! :D

 

EDIT: Code didn't work at the top (just above $my_email) :pardon:

ok, can you put this at the top of your script temporarily

echo '<pre>'.print_r($_POSt, true).'</pre>';

die();

and print out the output it generates (delete any sensitive information if you want, it's the keys of the array that I'm interested in)

 

Can you then delete the code from your script, and paste exactly what you have now

  • Author

Hi Jay,

 

I added the code you provided to the top of the script but when I submit the form, all I get now is an empty blank page. The source simply reads <pre></pre>

 

:sorry:

If this php is on the same page as your form can you delete the die() line. Otherwise can you submit your form (Also if the form method of sending data is GET can you change $_POST to $_GET)

  • Author

Hi Jay, the form is in contact.html file whilst the PHP script is in contact.php file.

 

I've edited the PHP script in the contact.php file as advised and when I submit the form, all I get is a blank page.

 

EDIT: Oh and method is get.

  • Author

Cheers Jay! Here's the code:

 

				<form class="cmxform" id="orderform" method="post" action="../order/order.php">
					<table width="92%" border="0" align="center" cellpadding="3"> 
                       	<tr>
							<td>
                               <label>Contact name</label>
                               <input type="text" style="width:181px; float:right;" name="contact name" class="required" />
							</td>
						</tr>
						<tr>
							<td>
                               <label>Company</label>
                               <input type="text" style="width:181px; float:right;" name="company" class="required" />
							</td>
						</tr>
						<tr>
							<td>
                               <label>Email</label>
                               <input type="text" style="width:181px; float:right;" name="email" class="required" />
							</td>
						</tr>
						<tr>
							<td>
                               <label>Phone number</label>
                               <input type="text" style="width:181px; float:right;" name="phone number" class="required" />
							</td>
						</tr>
                           <tr>
                           	<td class="right"> 
                               <label>Enquiring about</label> 
                               <textarea rows="4" name="enquiring_about" cols="30" style="float:right;" class="required"></textarea> 
							</td> 
						</tr>
                           <tr>
							<td style="padding-top: 15px; float:right;">
                               <input class="submit" type="submit" value="Submit"/>  
							<input type="reset" name="clear" id="clear" value="Clear" />
							</td>
						</tr>
						<tr>
                           	<td>
                               <label>Add me to your newsletter mailing list</label>
                               <input type="checkbox" style="float:right" name="Newsletter sign up" />
                               </td>
						</tr>
                       </table>
				</form>

Well you've said that the method is GET but according to your form it's POST

 

So with your form you only have one value you want changing to Yes from On and that's the newsletter signup. Firstly change the newsletter signup name to signup in the form then use the following at the top of your php script

if(isset($_POST['signup']) && $_POST['signup'] == 'On')\ $_POST['signup'] = 'Yes';

That should hopefully sort this. I'm not sure how you were getting nothing earlier with the <pre> code I had above if you submitted the form. It's very strange tbh

  • Author

Hi Jay,

 

I've added the code, submitted the form but on the thank you page I now get the following error at the top of the screen:

 

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /homepages/18/d229507269/htdocs/customers/customername/order/order.php on line 80

 

:blush1:

Wow, I've never seen that error message before. Can you paste the current script you have now in full for the php file

OK it's just the line I gave you from the looks of it. This must have added a \ for some reason. Remove the \ before $_POST in the line I posted above

  • Author

Here you go Jay!

 

<?php

$my_email = "xxxx@hotmail.com";

$from_email = "xxxxxxxx";

$errors = array();

if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}

if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{

$_REQUEST['email'] = trim($_REQUEST['email']);

if(substr_count($_REQUEST['email'],"@") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}

}

if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}

function recursive_array_check_blank($element_value)
{

global $set;

if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{

foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}

}

}

recursive_array_check_blank($_REQUEST);

if(!$set){$errors[] = "You cannot send a blank form";}

unset($set);

if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}

if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}

function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}

$message = build_message($_REQUEST);

$message = stripslashes($message);

$subject = "xxxxxxxxxxxxxx";

$subject = stripslashes($subject);

if($from_email)
{

$headers = "From: " . $from_email;
$headers .= PHP_EOL;
$headers .= "Reply-To: " . $_REQUEST['email'];

}
else
{

$from_name = "";

if(isset($_REQUEST['name']) && !empty($_REQUEST['name'])){$from_name = stripslashes($_REQUEST['name']);}

$headers = "From: {$from_name} <{$_REQUEST['email']}>";

}

mail($my_email,$subject,$message,$headers);

if(isset($_POST['signup']) && $_POST['signup'] == 'On') $_POST['signup'] = 'Yes';

?>

That line needs to go at the TOP of your code, not the bottom :) It's pointless changing the text after you've sent the email ;)

  • Author

LOL! Can you tell I'm **** at PHP? :blink:

 

Still didn't work (still says on). :cray:

ok well last attempt is to change the $_POST to $_REQUEST to see if that works, although if it does there's something wacky going on

 

I'll also point out that you shouldn't be using tables to format your form neatly. It can be accomplished with css (but we'll leave that for now :))

can you do

echo '<pre>'.print_r($_SERVER, true).'</pre>';

at the top of the script

and submit the contact form and print the output here

  • Author

Thanks Jay. Here you go!!

 

Array
(
   [CONTENT_LENGTH] => 599
   [CONTENT_TYPE] => application/x-www-form-urlencoded
   [DBENTRY] => /kunden/homepages/18/d229507269/htdocs:d0000#CPU 6 #MEM 10240 #CGI 346 #NPROC 12 #TAID 47675017 #WERB 0 #LANG 1 #STAT 1
   [DOCUMENT_ROOT] => /kunden/homepages/18/d229507269/htdocs
   [HTTP_ACCEPT] => application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
   [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.3
   [HTTP_ACCEPT_ENCODING] => gzip,deflate,sdch
   [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.8
   [HTTP_CACHE_CONTROL] => max-age=0
   [HTTP_CONNECTION] => keep-alive
   [HTTP_COOKIE] => __utmz=50933499.1268353853.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=50933499.1321877029.1268353853.1269082453.1269388828.7
   [HTTP_HOST] => www.creativewales.com
   [HTTP_ORIGIN] => http://www.creativewales.com
   [HTTP_REFERER] => http://www.creativewales.com/customers/xxxxxxxxxxxx/order/index.html
   [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1042 Safari/532.5
   [PATH] => /bin:/usr/bin
   [REDIRECT_DBENTRY] => /kunden/homepages/18/d229507269/htdocs:d0000#CPU 6 #MEM 10240 #CGI 346 #NPROC 12 #TAID 47675017 #WERB 0 #LANG 1 #STAT 1
   [REDIRECT_SCRIPT_URI] => http://www.creativewales.com/customers/xxxxxxxxxxxx/order/order.php
   [REDIRECT_SCRIPT_URL] => /customers/xxxxxxxxxxxx/order/order.php
   [REDIRECT_STATUS] => 200
   [REDIRECT_UNIQUE_ID] => S6zwIdTjHRYAAFhwuMM
   [REDIRECT_URL] => /customers/xxxxxxxxxxxx/order/order.php
   [REMOTE_ADDR] => 87.115.93.99
   [REMOTE_PORT] => 51096
   [sCRIPT_FILENAME] => /kunden/homepages/18/d229507269/htdocs/customers/xxxxxxxxxxxx/order/order.php
   [sCRIPT_URI] => http://www.creativewales.com/customers/xxxxxxxxxxxx/order/order.php
   [sCRIPT_URL] => /customers/xxxxxxxxxxxx/order/order.php
   [sERVER_ADDR] => 212.227.33.151
   [sERVER_ADMIN] => webmaster@creativewales.com
   [sERVER_NAME] => creativewales.com
   [sERVER_PORT] => 80
   [sERVER_SIGNATURE] => 
   [sERVER_SOFTWARE] => Apache
   [uNIQUE_ID] => S6zwIdTjHRYAAFhwuMM
   [GATEWAY_INTERFACE] => CGI/1.1
   [sERVER_PROTOCOL] => HTTP/1.1
   [REQUEST_METHOD] => POST
   [QUERY_STRING] => 
   [REQUEST_URI] => /customers/xxxxxxxxxxxx/order/order.php
   [sCRIPT_NAME] => /customers/xxxxxxxxxxxx/order/order.php
   [PATH_INFO] => /customers/xxxxxxxxxxxx/order/order.php
   [PATH_TRANSLATED] => /kunden/homepages/18/d229507269/htdocs/customers/xxxxxxxxxxxx/order/order.php
   [sTATUS] => 200
   [php_SELF] => /customers/xxxxxxxxxxxx/order/order.php
   [argv] => Array
       (
       )

   [argc] => 0
)

  • Author

LOL! Here you go! Bare in mind it's an order form for food. The checkbox I ticked was the top one (antipasti). All the HTML and form etc is correct.

 

Array
(
   [Preferred_Menu] => Classic Light Lunch
   [antipasti] => on
   [still_mineral_water_(1_ltr_bottle)] => 
   [sparkling_mineral_water_(1_ltr_bottle)] => 
   [Orange_juice_(1_ltr_carton)] => 
   [Pineapple_juice_(1_ltr_carton)] => 
   [Grapefruit_juice_(1_ltr_carton)] => 
   [Apple_juice_(1_ltr_carton)] => 
   [Tomato_juice_(1_ltr_carton)] => 
   [Elderflower_Presse_(75cl_bottle)] => 
   [Cranberry_Juice_Drink_(1_ltr_carton)] => 
   [contact_name] => Aled Mann
   [phone_number] => 07xxxxxxxxx
   [email] => aledmann@xxxxxxxxxx.com
   [delivery_address] => here
   [Date] => 25/03/2010
   [Time_of_lunch] => 1pm
   [How_many_people] => 29
   [Plates] => Paper Plates
   [serviettes] => No thanks
   [anything_else] => no
   [__utmz] => 50933499.1268353853.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
   [__utma] => 50933499.1321877029.1268353853.1269082453.1269388828.7
)

OK Try this at the top of your script

foreach($_REQUEST as &$value) {
if(strtolower($value) == 'on') $value = 'Yes';
}

Fingers crossed...............

  • Author

Nooooooooo! :shok:

 

Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /homepages/18/d229507269/htdocs/customers/xxxxxxx/order/order.php on line 3

foreach($_REQUEST as $k => $value) {

if(strtolower($value) == 'on') $_REQUEST[$k] = 'Yes';

}

 

If that doesn't work I give in

What version of php are you running?

 

  • Author

Oooooooh my God.....IT WORKED!! LOL!

 

You are a true PHP Jedi master. Thanks a lot for all your help Jay, really, you went above and beyond what most would have done!

 

Thanks again! :clapping:

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.