Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

added checkboxes don't work on Contact us / RFQ page


pushlatency

Recommended Posts

Posted

Hi, i've been working on creating a new request quote page from the contact us page.

 

I've basically added a slew of new fields, drop downs and checkboxes, with all of the info being collected and e-mailed as normal. You can see it here:

 

www.tekcast.com/cre/rfq.php

 

Now the issue I'm having is that the information I receive from this form always shows that every checkbox has been selected even when this isn't the case.

 

Here's the code for a given checkbox with the name "enquiry_int_1":

$enquiry_int_1 = (tep_db_prepare_input($HTTP_POST_VARS['enquiry_int_1']) == 'on') ? '1' : '0';
$enquiry_int_1_string = '';
if (tep_not_null($enquiry_int_1)) { $enquiry_int_1_string = ENTRY_RFQ_ENQUIRY_INT_1 . ', ';   }

 

And then enquiry_int_1_string is passed on and sent to an e-mail

Anyways, it for some reason believes that the checkboxes are always selected and i'd like to get it to be more truthful.

 

I hope this is a reasonably clear explaination and any help is appreciated. Thanks.

Harris

Posted

Because you're checking against tep_not_null():

 

  function tep_not_null($value) {
if (is_array($value)) {
  if (sizeof($value) > 0) {
	return true;
  } else {
	return false;
  }
} else {
  if (($value != '') && (strtolower($value) != 'null') && (strlen(trim($value)) > 0)) {
	return true;
  } else {
	return false;
  }
}
 }

 

Which will return false IF AND ONLY IF

 

$value has a length of 0

$value is an empty string

$value does not contain the string 'null'

$value does not contain only spaces or line breaks which would make it an empty string after trim()

 

Since the $value you're testing is always either '1' or '0', this function will always return true. '1' or '0' is a string of length 1, so you pass the first test. '1' or '0' is not an empty string, so you pass the second. '1' or '0' is not equal to the string 'null', so you pass the third test. '1' or '0' contains more than just spaces or linebreaks, so after trim() it still has a length of 1, so it passes the fourth test.

 

It's not that the code thinks the checkboxes are always selected, it's that your if statement will always return true in this case:

 

$enquiry_int_1 = (tep_db_prepare_input($HTTP_POST_VARS['enquiry_int_1']) == 'on') ? '1' : '0';
$enquiry_int_1_string = '';
if (tep_not_null($enquiry_int_1)) { $enquiry_int_1_string = ENTRY_RFQ_ENQUIRY_INT_1 . ', ';   }

 

You want something like:

 

$enquiry_int_1 = (tep_db_prepare_input($HTTP_POST_VARS['enquiry_int_1']) == 'on') ? '1' : '0';
$enquiry_int_1_string = '';
if ($enquiry_int_1 == '1') { $enquiry_int_1_string = ENTRY_RFQ_ENQUIRY_INT_1 . ', ';   }

 

Of course you can simplify it by:

 

$enquiry_int_1_string = '';
if (tep_db_prepare_input($HTTP_POST_VARS['enquiry_int_1']) == 'on') { $enquiry_int_1_string = ENTRY_RFQ_ENQUIRY_INT_1 . ', ';   }

Contributions

 

Discount Coupon Codes

Donations

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...