FORUMS: list search recent posts

PHP not sending checkbox info on contact form

COW Forums : Web Design

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Clint MilnerPHP not sending checkbox info on contact form
by on Jan 16, 2009 at 10:38:15 am

Many thanks in advance!

I have a working contact form on my new website, and I have an HTML talking to a PHP mail script. All the text boxes are communicating fine with script, it's just a couple checkboxes that aren't showing up in the form that is sent to my email.

http://www.alpha-duplication.com/howies/pages/info/quote.html
( Line 175 in the HTML code)

Line 28 and 68 in the PHP script:
<?php

$mailto = 'MYEMAILADDRESS@MYDOMAIN.com';
$subject = "Quote Request Form" ;

$formurl = "http://www.alpha-duplication.com/howies/pages/info/quote.html" ;
$errorurl = "http://www.alpha-duplication.com/" ;
$thankyouurl = "http://www.alpha-duplication.com/howies/" ;

$email_is_required = 1;
$name_is_required = 1;
$uself = 0;
$use_envsender = 1;
$use_webmaster_email_for_from = 1;
$use_utf8 = 1;

$headersep = (!isset( $uself ) || ($uself == 0)) ? "rn" : "n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
$envsender = "-f$mailto" ;
$name = $_POST['name'];
$email = $_POST['email'];
$company = $_POST['company'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$phone = $_POST['phone'];
$details = $_POST['details'];
$addToList = $_POST['addToList'];
$noEmailList = $_POST['noEmailList'];
$comments = $_POST['comments'] ;


$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (($email_is_required && (empty($email) || !ereg("@", $email))) || ($name_is_required && empty($name))) {
header( "Location: $errorurl" );
exit ;
}
if ( ereg( "[rn]", $name ) || ereg( "[rn]", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (empty($email)) {
$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

if (get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}

$messageproper =
"This message was sent from:n" .
"$http_referrern" .
"------------------------------------------------------------n" .
"Name of sender: $namen" .
"Email of sender: $emailn" .
"------------------------- COMMENTS -------------------------nn" .
"Company: $companyn" .
"Address: $addressn" .
"Postcode: $postcoden" .
"Phone Number: $phonen" .
"Project Details: $commentsn" .
"Add to Email List? $addToListn" .
"Don't add to Email List: $noEmailListn" .
"nn------------------------------------------------------------n" ;

$headers =
"From: "$name" <$fromemail>" . $headersep . "Reply-To: "$name" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.13.0" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

if ($use_envsender) {
mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
mail($mailto, $subject, $messageproper, $headers );
}

header( "Location: $thankyouurl" );

?>


Return to posts index

Abraham ChaffinRe: PHP not sending checkbox info on contact form
by on Jan 16, 2009 at 2:57:55 pm

Your check boxes need values assigned to them. The value of the property is the value of the variable that is past if the box is checked. In your php page that receives the form information you should check first to see if the value is the assigned value of the checkbox - usually "1" or "on" or something and then you can do and else to assign an alternate variable.


if($_POST[addToList]==1){
  $whatever="whatever";
}else{
  $whatever="somethine else";
}


Abraham


Return to posts index

Curtis ThompsonRe: PHP not sending checkbox info on contact form
by on Jan 16, 2009 at 3:34:37 pm

hello...

i assume they don't show up if not checked and do show up if checked? if a checkbox is not checked, it becomes essentially a non-entity to the back end...

if you want to have a nice "yes/no" style entry, you can switch it to something like:

$addToList = ($_POST['addToList'] == "") ? "No" : "Yes";

hope that helps!

sitruc





Return to posts index


Clint MilnerRe: PHP not sending checkbox info on contact form
by on Jan 19, 2009 at 10:34:47 am

Hi Andrew and Curtis,

Thanks for the replies. I think I'll get this PHP thing one day.

As it is right now, when either box is checked, nothing is reported back to my email. All the other fields send what is in their input boxes, but just not the two checkboxes.

If that is the case, where should I go from here?


Many thanks guys,
Clint



Return to posts index

Clint MilnerRe: PHP not sending checkbox info on contact form
by on Jan 19, 2009 at 3:47:20 pm

Hi Guys,

I've sorted it!

In my HTML, I added value="1" as one of the checkbox's properties, and then added the if statement that Abraham suggested, and after a bit of fine-tuning, it seems to be working correctly.


Many thanks guys, I usually spend my time in the Flash forum, but it's good to see that the Cow is well oiled all the way around.

Clint




Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]