Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Web Design (WordPress, Joomla, etc.) PHP not sending checkbox info on contact form

  • PHP not sending checkbox info on contact form

    Posted by Clint Milner on January 16, 2009 at 10:38 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.

    https://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 = 'MY************@******IN.com';
    $subject = "Quote Request Form" ;

    $formurl = "https://www.alpha-duplication.com/howies/pages/info/quote.html" ;
    $errorurl = "https://www.alpha-duplication.com/" ;
    $thankyouurl = "https://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)) ? "\r\n" : "\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( "[\r\n]", $name ) || ereg( "[\r\n]", $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_referrer\n" .
    "------------------------------------------------------------\n" .
    "Name of sender: $name\n" .
    "Email of sender: $email\n" .
    "------------------------- COMMENTS -------------------------\n\n" .
    "Company: $company\n" .
    "Address: $address\n" .
    "Postcode: $postcode\n" .
    "Phone Number: $phone\n" .
    "Project Details: $comments\n" .
    "Add to Email List? $addToList\n" .
    "Don't add to Email List: $noEmailList\n" .
    "\n\n------------------------------------------------------------\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" );

    ?>

    Clint Milner replied 17 years, 3 months ago 3 Members · 4 Replies
  • 4 Replies
  • Abraham Chaffin

    January 16, 2009 at 2:57 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

  • Curtis Thompson

    January 16, 2009 at 3:34 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

  • Clint Milner

    January 19, 2009 at 10:34 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

  • Clint Milner

    January 19, 2009 at 3:47 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

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy