PHP form checkbox problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JohnJJones
Forum Newbie
Posts: 4
Joined: Tue Nov 28, 2006 9:48 pm

PHP form checkbox problem.

Post 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.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

We need to see some actual php code, not just what it generates.
JohnJJones
Forum Newbie
Posts: 4
Joined: Tue Nov 28, 2006 9:48 pm

Post 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" );
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
JohnJJones
Forum Newbie
Posts: 4
Joined: Tue Nov 28, 2006 9:48 pm

Post 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 :)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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';
JohnJJones
Forum Newbie
Posts: 4
Joined: Tue Nov 28, 2006 9:48 pm

Post 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!
Post Reply