Radio buttons fail

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
mguise
Forum Newbie
Posts: 21
Joined: Mon Mar 21, 2011 1:28 pm

Radio buttons fail

Post by mguise »

Hi community. The radio buttons on my form suddenly stopped working. For the life of me I can’t figure out why. Everything seems to look fine. I did some moving around on servers so I wonder if something got messed up during the transfer. I’m wondering if a new version of PHP was installed and made something obsolete. I was wondering if someone could take a look. Thank you in advance for your advise.

Code: Select all

<form action="brian_1.php" method="post" name="form1" id="form1">
<input name="name" type="text" id="name" size="30" tabindex="1"/>
Company if Applicable:
<input name="company" type="text" id="company" size="30" tabindex="2"/>
Phone: 
<input name="phone" type="text" id="phone" tabindex="3" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="12"/>
Example: XXXXXXXXXX
Alternate Phone: 
<input name="altphone" type="text" id="altphone" tabindex="4" onkeypress="return formatPhone(event,this)" onkeydown="return getKey(event,this)" size="13" maxlength="13"/> 
Example: XXXXXXXXXX
Street Address:<input name="mail" type="text" id="mail" size="60" tabindex="5"/>
City, State, Zip Code: 
<input name="city" type="text" id="city" size="60" tabindex="5"/>
E-mail: 
<input name="emai" type="text" id="emai" size="60" tabindex="6"/>
Would you like to be part of our mailing list?
<label><input type="radio" name="list" value="Yes" id="RadioGroup1_0" tabindex="7"/>Yes</label><label><input type="radio" name="list" value="No" id="RadioGroup1_1" tabindex="8"/>No</label>
Are you interested in volunteering for upcoming events?
<label><input type="radio" name="volunteer" value="Yes" id="RadioGroup2_0" tabindex="9"/>Yes</label><label><input type="radio" name="volunteer" value="No" id="RadioGroup2_1" tabindex="10"/>No</label>
Are you interested in becoming a sponsor by receiving opportunities to advertise through us?
<label><input type="radio" name="opportunities" value="Yes" id="RadioGroup3_0" tabindex="11"/>Yes</label><label><input type="radio" name="opportunities" value="No" id="RadioGroup3_1" tabindex="12"/>No</label>
Would you like to join our efforts by offering your services or products to further our cause?
<label><input type="radio" name="cause" value="Yes" id="RadioGroup4_0" tabindex="15"/>Yes</label><label><input type="radio" name="cause" value="No" id="RadioGroup4_1" tabindex="16"/>No</label>
If so, in what ways would you like to contribute?
<textarea name="contribute" cols="60" rows="4"></textarea>
<input type="submit" name="Submit" value="Sumbit"  /><input type="reset" name="reset" id="reset" value="Clear" />
</form>

Code: Select all

<?php
/* Email Variables */
$emailSubject = 'Contact Form';
$webMaster = 'brianewagnerfund@gmail.com';
$webMaster = 'matt@webskillsplus.com';
//$webMaster = 'murrterr@rcn.com';
/* Data Variables */
$name = $_POST['name'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$altphone = $_POST['altphone'];
$mail = $_POST['mail'];
$city = $_POST['city'];
$emai = $_POST['emai'];
if (isset($_POST["submit"])) {
echo $_POST["list"];
}
if (isset($_POST["submit"])) {
echo $_POST["volunteer"];
}
if (isset($_POST["submit"])) {
echo $_POST["opportunities"];
}
if (isset($_POST["submit"])) {
echo $_POST["cause"];
}
$contribute = $_POST['contribute'];
$body = <<<EOD
\r\n \r\n <br>
Name(s): $name \r\n <br>
Company if Applicable: $company \r\n <br>
Phone: $phone \r\n <br>
Alternate Phone: $altphone \r\n <br>
Street Address: $mail \r\n <br>
City, State, Zip Code: $city \r\n <br>
Email:  $emai \r\n <br>
Would you like to be part of our mailing list? $list \r\n <br>
Are you interested in volunteering for upcoming events? $volunteer \r\n <br>
Are you interested in becoming a sponsor by receiving opportunities to advertise through us? $opportunities \r\n <br>
Would you like to join our efforts by offering your services or products to further our cause? $cause \r\n <br>
If so, in what ways would you like to contribute?  $contribute \r\n <br>
EOD;
$from = "From: BrianEWagnerFund@gmail.com\r\n";
$from .= "Reply-To: ".$emai."\r\n";
$from .= "Content-type: text/html\r\n";
mail($webMaster, $emailSubject, $body, $from);
/* Results rendered as HTML */
echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.brianewagnerfund.org/thankyou.html\">";
?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Radio buttons fail

Post by Celauran »

mguise wrote:The radio buttons on my form suddenly stopped working.
Can you elaborate on this, please? Looks fine to me, too, so at least knowing what to look for would be helpful.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Radio buttons fail

Post by Christopher »

When you say "stopped working" do you mean they don't display correctly or that you no longer receive values from them? Or something else?
(#10850)
mguise
Forum Newbie
Posts: 21
Joined: Mon Mar 21, 2011 1:28 pm

Re: Radio buttons fail

Post by mguise »

My apologies, yes I never receive values from them, that is, just the radio buttons. Everything else is working correctly. When you fill out the form and select yes or no for the radio buttons it sends everything via email except for any radio button answers. Any ideas?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Radio buttons fail

Post by Christopher »

You might want to try isset($_POST["Submit"])
(#10850)
mguise
Forum Newbie
Posts: 21
Joined: Mon Mar 21, 2011 1:28 pm

Re: Radio buttons fail

Post by mguise »

This is a list of the errors I am getting.

Code: Select all

Notice: Undefined index: name in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 31

Notice: Undefined index: company in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 33

Notice: Undefined index: phone in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 35

Notice: Undefined index: altphone in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 37

Notice: Undefined index: mail in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 39

Notice: Undefined index: city in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 41

Notice: Undefined index: emai in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 43

Notice: Undefined index: contribute in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 61

Notice: Undefined variable: list in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 85

Notice: Undefined variable: volunteer in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 87

Notice: Undefined variable: opportunities in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 89

Notice: Undefined variable: cause in /var/www/vhosts/www.brianewagnerfund.org/httpdocs/brian_1.php on line 91
I did what you said and fixed

Code: Select all

($_POST["Submit"])
I'm still having issues. Any ideas?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Radio buttons fail

Post by Celauran »

Please post the contents of brian_1.php, since that's where the errors are.
mguise
Forum Newbie
Posts: 21
Joined: Mon Mar 21, 2011 1:28 pm

Re: Radio buttons fail

Post by mguise »

Here you go Celauran, thanks in advance for your help

Code: Select all

<?php




/* Email Variables */



$emailSubject = 'Contact Form';



$webMaster = 'brianewagnerfund@gmail.com';

$webMaster = 'matt@webskillsplus.com';

//$webMaster = 'murrterr@rcn.com';



/* Data Variables */



$name = $_POST['name'];

$company = $_POST['company'];

$phone = $_POST['phone'];

$altphone = $_POST['altphone'];

$mail = $_POST['mail'];

$city = $_POST['city'];

$emai = $_POST['emai'];

if (isset($_POST["submit"])) {
echo $_POST["list"];
}

if (isset($_POST["submit"])) {
echo $_POST["volunteer"];
}

if (isset($_POST["submit"])) {
echo $_POST["opportunities"];
}

if (isset($_POST["submit"])) {
echo $_POST["cause"];
}

$contribute = $_POST['contribute'];



$body = <<<EOD

\r\n \r\n <br>

Name(s): $name \r\n <br>

Company if Applicable: $company \r\n <br>

Phone: $phone \r\n <br>

Alternate Phone: $altphone \r\n <br>

Street Address: $mail \r\n <br>

City, State, Zip Code: $city \r\n <br>

Email:  $emai \r\n <br>

Would you like to be part of our mailing list? $list \r\n <br>

Are you interested in volunteering for upcoming events? $volunteer \r\n <br>

Are you interested in becoming a sponsor by receiving opportunities to advertise through us? $opportunities \r\n <br>

Would you like to join our efforts by offering your services or products to further our cause? $cause \r\n <br>

If so, in what ways would you like to contribute?  $contribute \r\n <br>

EOD;





$from = "From: BrianEWagnerFund@gmail.com\r\n";

$from .= "Reply-To: ".$emai."\r\n";

$from .= "Content-type: text/html\r\n";



mail($webMaster, $emailSubject, $body, $from);




/* Results rendered as HTML */


echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.brianewagnerfund.org/thankyou.html\">";


?>
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Radio buttons fail

Post by Celauran »

The line numbers don't match your error log, but you're not first checking if $_POST actually contains any data. Wrap the whole mess in

Code: Select all

if (!empty($_POST)) {
// code here
}
and consider adding checks against each index, providing default values where you can, and failing outright if required values aren't set.
mguise
Forum Newbie
Posts: 21
Joined: Mon Mar 21, 2011 1:28 pm

Re: Radio buttons fail

Post by mguise »

With some help I got it to successfully work. Thanks for all of your advise. The following works.

Code: Select all

<?php




if (isset($_POST["submit"])) 
{
	/* Email Variables */
	$emailSubject = 'Contact Form';
	$webMaster = 'brianewagnerfund@gmail.com';
	$webMaster = 'matt@webskillsplus.com';
	//$webMaster = 'murrterr@rcn.com';
	/* Data Variables */
	$name = $_POST['name'];
	$company = $_POST['company'];
	$phone = $_POST['phone'];
	$altphone = $_POST['altphone'];
	$mail = $_POST['mail'];
	$city = $_POST['city'];
	$emai = $_POST['emai'];
	$list = $_POST["list"];
	$volunteer =  $_POST["volunteer"];
	$opportunities = $_POST["opportunities"];
	$cause = $_POST["cause"];
	$contribute = $_POST['contribute'];
	$body = "
	<br><br>
	Name(s): $name<br>
	Company if Applicable: $company<br>
	Phone: $phone<br>
	Alternate Phone: $altphone<br>
	Street Address: $mail<br>
	City, State, Zip Code: $city<br>
	Email:  $emai<br>
	Would you like to be part of our mailing list? $list<br>
	Are you interested in volunteering for upcoming events? $volunteer<br>
	Are you interested in becoming a sponsor by receiving opportunities to advertise through us? $opportunities<br>
	Would you like to join our efforts by offering your services or products to further our cause? $cause<br>
	If so, in what ways would you like to contribute?  $contribute<br>";
	$from = "From: BrianEWagnerFund@gmail.com\r\n";
	$from .= "Reply-To: ".$emai."\r\n";
	$from .= "Content-type: text/html\r\n";
	mail($webMaster, $emailSubject, $body, $from);
	/* Results rendered as HTML */
	header("Location: http://www.brianewagnerfund.org/thankyou.html");
}

?>

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Radio buttons fail

Post by Christopher »

Code: Select all

if (isset($_POST["submit"])) 
A sidenote, in many browsers you can submit a form by pressing Enter when in a field. Some browsers will not sent the submit button in this case. A check might be a hidden field or better to check $_SERVER['REQUEST_METHOD'] to see if it is POST.
(#10850)
Post Reply