mguise Posted July 10, 2014 Share Posted July 10, 2014 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. <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> <?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\">"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/ Share on other sites More sharing options...
cyberRobot Posted July 10, 2014 Share Posted July 10, 2014 Are you getting any errors? Note that you can show all PHP errors by adding the following to the top of your PHP script: <?php error_reporting(E_ALL); ini_set('display_errors', 1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1484545 Share on other sites More sharing options...
cyberRobot Posted July 10, 2014 Share Posted July 10, 2014 It looks like your script is dependent on Register Globals being enabled. For example, one of your radio buttons is named "list". In the PHP script that processes the form, it looks like you're trying to use the radio button's value here: Would you like to be part of our mailing list? $list \r\n <br> With the Register Globals settings disabled / removed (note that it was deprecated in PHP 5.3 and removed in 5.4), $list is now undefined. Trying using $_POST instead: Would you like to be part of our mailing list? $_POST['list'] \r\n <br> Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1484546 Share on other sites More sharing options...
fastsol Posted July 10, 2014 Share Posted July 10, 2014 You're checking for $_POST['submit'] but your form is using Submit. So $_POST['submit'] is not the same as $_POST['Submit']. There are plenty of other issues in you script but that is why you're not seeing many things echoed to the page. Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1484547 Share on other sites More sharing options...
mguise Posted July 15, 2014 Author Share Posted July 15, 2014 cyberRobot this is a list of the errors I am getting. 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 replaced Would you like to be part of our mailing list? $list \r\n <br> with Would you like to be part of our mailing list? $_POST['list'] \r\n <br> and I get a syntax error. It makes the php page fail. I see nothing. Do you have any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1485364 Share on other sites More sharing options...
fastsol Posted July 15, 2014 Share Posted July 15, 2014 Those line numbers don't really match up to the codes you have provided. Is the form and the validation on the same page? Eitehr way, you need to wrap the validation code in an if(isset($_POST['submit'])) // possibly $_POST['Submit'] depending on if you changed it like I said previously. { // Validation code here. } That will keep the errors from showing at least until the form is submitted. Here is a tutorial on a much better way to validate a form and the logic behind it. http://amecms.com/article/How-to-validate-a-form-the-right-way Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1485374 Share on other sites More sharing options...
mguise Posted July 18, 2014 Author Share Posted July 18, 2014 fastsol the form and validation are are on separate pages. I made the changes as you suggested. I changed it to if (isset($_POST["submit"])) { echo $_POST["list"]; } But I still get a list of the following errors. YesYesYesYes 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 Since the numbers are not matching up, here is the lines that it is referring to. 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> Any ideas? I apologize for my novice questions. I don't deal with this stuff every day. Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1485654 Share on other sites More sharing options...
fastsol Posted July 18, 2014 Share Posted July 18, 2014 There are a number of things wrong with your code, to many to list honestly! I reworked the code for you so you can see the right way to do this. I did not take in to account any security, so you seriously should expand on that before using this on a live site. I got rid of the EOD stuff, I really don't konw why people use that, at least I never have and I don't like the syntax it uses. Since I didn't take the time to remake your actualy form, I can't say this is perfect, but it doesn't throw any syntax errors when loaded. 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"); } You truly should take a look and follow the tutorial link I previously posted so you can integrate the security it needs. Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1485659 Share on other sites More sharing options...
mguise Posted July 21, 2014 Author Share Posted July 21, 2014 Thank you fastsol. It works perfectly. I will take a look at the tutorial link you sent me. I appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/289688-radio-buttons-fail/#findComment-1485823 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.