Page 1 of 1

PHP form checkbox problem.

Posted: Tue Nov 28, 2006 9:49 pm
by JohnJJones
I'm very new to PHP and I want to create a customer feedback form on a website.

Here and the relevant links:
http://www.macquariemint.com/sendmail.php
http://www.macquariemint.com/customerfeedback.html
http://www.macquariemint.com/thankyou.html

So far I've only implemented the following sections:
First Name
Last Name
E-mail Address
Street Address
City/Suburb
State
Postcode
Australian Decimal Coins and/or Banknotes check box.

What I want to happen is; a user inputs the data, its get emailed to my account and they are redirected to the thank you page.

The problem I'm having is with the check box. It works fine when the box is selected - but when its not selected I get the following error:

Notice: Undefined index: decimal in D:\Inetpub\Macquariemint\sendmail.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at D:\Inetpub\Macquariemint\sendmail.php:10) in D:\Inetpub\Macquariemint\sendmail.php on line 15

I need the data to be emailed to me and the user redirected regardless if any of the check boxes are selected or not.

Can anyone give me a hand with the check box problem I am having, it would be greatly appreciated.

Posted: Tue Nov 28, 2006 10:04 pm
by Zoxive
We need to see some actual php code, not just what it generates.

Posted: Tue Nov 28, 2006 10:17 pm
by JohnJJones

Code: Select all

<?

  $firstname = $_REQUEST['firstname'];
  $lastname = $_REQUEST['lastname'];
  $emailaddress = $_REQUEST['emailaddress'];
  $streetaddress = $_REQUEST['streetaddress'];
  $citysuburb = $_REQUEST['citysuburb'];
  $state = $_REQUEST['state'];
  $postcode = $_REQUEST['postcode'];
  $collectcomments = $_REQUEST['collectcomments'];
  $suggestion = $_REQUEST['suggestion'];
  $comments = $_REQUEST['comments'];
  
  
  mail( "jjones@downies.com", "Feedback Form Results",
    "First Name: $firstname\nLast Name: $lastname\nEmail address: $emailaddress\nStreet Address: $streetaddress\nCity/Suburb: $citysuburb\nState: $state\nPostcode: $postcode\nOther Collecting Comments: $collectcomments\nFuture Offers: $suggestion\nOther Comments: $comments", "From: $emailaddress" );
  header( "Location: http://www.macquariemint.com/thankyou.html" );
?>

Posted: Tue Nov 28, 2006 10:28 pm
by volka
An unselected checkbox is not sent at all as http parameter, check the existance via isset.
JohnJJones wrote:Notice: Undefined index: decimal in D:\Inetpub\Macquariemint\sendmail.php on line 10
The word decimal does not appear in the code snippet you've posted here.

Posted: Tue Nov 28, 2006 10:31 pm
by JohnJJones
Yeah, I accidentally posted the newest version of the code; where the decimal portion has been temporarily removed.

I'm currently reading the link you gave so I'll give some of the stuff they suggest a try. Thanks :)

Posted: Tue Nov 28, 2006 10:38 pm
by volka
should be something like

Code: Select all

if ( isset($_REQUEST['decimal']) ) {
	$decimal = 'decimal set';
}
else {
	$decimal = 'decimal not set';
}
// or shorter
$decimal = isset($_REQUEST['decimal']) ? 'decimal set' : 'decimal not set';

Posted: Tue Nov 28, 2006 10:51 pm
by JohnJJones

Code: Select all

  $decimal = isset($_REQUEST['decimal']) ? 'Yes' : 'No';
Is what I'm after. Thanks alot for that.

I may need some assistance with 'radio' elements next... But I'll try a few things before I bug you guys again.

Thank you again, its just what I was after!