PHP form Radio Buttons

Hi there, I’m trying to create a PHP form and it always selects the first option when you select a radio button can anyone help?

[php]/**

  • Quotation Page
    */
    global $company;

if (isset($_REQUEST[‘function’])&&$_REQUEST[‘function’]==‘add’ ) {
if (isset($_REQUEST[‘fullname’])) {
$fullname = $_REQUEST[‘fullname’];
}
if (isset($_REQUEST[‘streetaddress’])) {
$streetaddress = $_REQUEST[‘streetaddress’];
}
if (isset($_REQUEST[‘city’])) {
$city = $_REQUEST[‘city’];
}
if (isset($_REQUEST[‘postalcode’])) {
$postalcode = $_REQUEST[‘postalcode’];
}
if (isset($_REQUEST[‘telephone’])) {
$telephone = $_REQUEST[‘telephone’];
}
if (isset($_REQUEST[‘faxnumber’])) {
$faxnumber = $_REQUEST[‘faxnumber’];
}
if (isset($_REQUEST[‘emailaddress’])) {
$emailaddress = $_REQUEST[‘emailaddress’];
}
if (isset($_REQUEST[‘response’])) {
$response = $_REQUEST[‘response’];
}
if (isset($_REQUEST[‘horsename’])) {
$horsename = $_REQUEST[‘horsename’];
}
if (isset($_REQUEST[‘sirename’])) {
$sirename = $_REQUEST[‘sirename’];
}
if (isset($_REQUEST[‘damname’])) {
$damname = $_REQUEST[‘damname’];
}
if (isset($_REQUEST[‘sex’])) {
$sex = $_REQUEST[‘sex’];
}
if (isset($_REQUEST[‘age’])) {
$age = $_REQUEST[‘age’];
}
if (isset($_REQUEST[‘horse’])) {
$horse = $_REQUEST[‘horse’];
}
if (isset($_REQUEST[‘purchaseprice’])) {
$purchasePrice = $_REQUEST[‘purchaseprice’];
}
if (isset($_REQUEST[‘insureamount’])) {
$insureamount = $_REQUEST[‘insureamount’];
}
if (isset($_REQUEST[‘comments’])) {
$comments = $_REQUEST[‘comments’];
}
if (isset($_REQUEST[‘replymail’])) {
$replymail = $_REQUEST[‘replymail’];
}
$disp = ‘

’ .
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
‘’.
Request a Quote
Full name: ’.$fullname.’
Street Address: ’.$streetaddress.’
City: ’.$city.’
Postal Code: ’.$postalcode.’
Telephone: ’.$telephone.’
Fax Number: ’.$faxnumber.’
email Address: ’.$emailaddress.’
Response: ’.$response.’
Horse Name: ’.$horsename.’
Sire Name: ’.$sirename.’
Dam Name: ’.$damname.’
Sex: ’.$sex.’
Age: ’.$age.’
Horse: ’.$horse.’
Purchase Price: ’.$purchaseprice.’
Insure Amount: ’.$insureamount.’
Comments: ’.$comments.’
Comments: ’.$replymail.’
’;
$message = new Message();
$message->setCompanyId($company->getCompanyID());
$message->setCampaignId(0);
$message->setContactId(0);
$message->setMesageTemplateId(0);
$message->setMessageSubject("Request a Quote: ".$fullname);
$message->setMessageType(“EMAIL”);
$message->setMessageBilled(“0”);
$message->setMessageText($disp);
$message->setEmail_sms(‘The recipients email address goes here’);
$message->setMessageCost(“0.23”);
$message->setMessageDate(date(‘Y-m-d H:i:s’));
$message->setStatus(“QUEUED”);
$sc = $message->save();
?>

Back home

  • Request a quote

  • Thank you <?= $full_name ?>, your request will be dealt with shortly

<?php } else { ?>

Back home

  • Request a quote

  • Name
  • Street Address
  • City
  • Postal Code
  • Telephone
  • Fax
  • Email Address
  • How would you like to respond?
    Email Phone Fax
  • Name of the horse insured?
  • Sire
  • Dam
  • Sex
    Stallion Gelding
  • Age
  • Type of horse:
                             </tr>
                        </table>
                    </li>
                     <li>
                        <strong>Purchase price of horse:</strong>
                        <input name='purchaseprice' id='purchaseprice' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Value you would like to insure for:</strong>
                        <input name='insureamount' id='insureamount' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Comments or queries:</strong>
                    </li>
                    <li>
                        <textarea cols='30' rows='5' name='comments' id='comments' class="quoteinput"></textarea>
                    </li>
                    <li>
                        <strong>Would you like an email to confirm your mail?</strong>
                        <table align="right">
                            <tr>
                             <td><input type='checkbox' id='replymail' name='replymail' value='reply'></td>
                            </tr>
                        </table>
                    </li>
                    <li>
                        <input type="Button" onClick='SendQuote()' name="submit" value="" class="submitbutton">
                    </li> 
                </ul>
            </form>
           </div><!--Left Col-->
    
    [/php]
    Racing Breeding Showjumping Dressage
    Showing Eventing Endurance Hacking
    Equitation Polo Polocrosse
     Other 

I tested this script and I dont have any problems with the radio buttons.
If this is your final script it wont work, you forget to open your php script [php]<?php [/php]
You also forget to close your ‘else’ at the end of your page. [php]

<?php } else { ?>[/php]

so add another [php]<?php }//Closing else ?>[/php]

Also note that your button does not have a value:
[php][/php]

Thanks for the help, I’ve added in the code with the PHP open and close as it stands, when you select
say for instance sex Gelding (Which is the second option) does it send that variable?

I tried adding the else if at the bottom it only made the other PHP tag turn black

Thanks for all you help so far.

<?php
/**
 * Quotation Page
 */
require_once('include/global.include.php');

require_once(GATEWAY_INCLUDE_DIR.'message.class.php');

global $company;

if (isset($_REQUEST['function'])&&$_REQUEST['function']=='add' ) {
	    if (isset($_REQUEST['fullname'])) { 
			$fullname = $_REQUEST['fullname'];
		}	
		if (isset($_REQUEST['streetaddress'])) { 
			$streetaddress = $_REQUEST['streetaddress'];
		}	
		if (isset($_REQUEST['city'])) { 
			$city = $_REQUEST['city'];
		}	
		if (isset($_REQUEST['postalcode'])) { 
			$postalcode = $_REQUEST['postalcode'];
		}	
		if (isset($_REQUEST['telephone'])) { 
			$telephone = $_REQUEST['telephone'];
		}
		if (isset($_REQUEST['faxnumber'])) { 
			$faxnumber = $_REQUEST['faxnumber'];
		}	
		if (isset($_REQUEST['emailaddress'])) { 
			$emailaddress = $_REQUEST['emailaddress'];
		}
		if (isset($_REQUEST['response'])) { 
			$response = $_REQUEST['response'];
		}
		if (isset($_REQUEST['horsename'])) { 
			$horsename = $_REQUEST['horsename'];
		}	
		if (isset($_REQUEST['sirename'])) { 
			$sirename = $_REQUEST['sirename'];
		}
		if (isset($_REQUEST['damname'])) { 
			$damname = $_REQUEST['damname'];
		}	
		if (isset($_REQUEST['sex'])) { 
			$sex = $_REQUEST['sex'];
		}
		if (isset($_REQUEST['age'])) { 
			$age = $_REQUEST['age'];
		}	
		if (isset($_REQUEST['horse'])) { 
			$horse = $_REQUEST['horse'];
		}	
		if (isset($_REQUEST['purchaseprice'])) { 
			$purchasePrice = $_REQUEST['purchaseprice'];
		}	
		if (isset($_REQUEST['insureamount'])) { 
			$insureamount = $_REQUEST['insureamount'];
		}
		if (isset($_REQUEST['comments'])) { 
			$comments = $_REQUEST['comments'];
		}
		if (isset($_REQUEST['replymail'])) { 
			$replymail = $_REQUEST['replymail'];
		}
		$disp = '<table>' .
					'<tr><td colspan="2">Request a Quote</td></tr>'.
					'<tr><td>Full name:</td><td>'.$fullname.'</td></tr>'.
					'<tr><td>Street Address:</td><td>'.$streetaddress.'</td></tr>'.
					'<tr><td>City:</td><td>'.$city.'</td></tr>'.
					'<tr><td>Postal Code:</td><td>'.$postalcode.'</td></tr>'.
					'<tr><td>Telephone:</td><td>'.$telephone.'</td></tr>'.
					'<tr><td>Fax Number:</td><td>'.$faxnumber.'</td></tr>'.
					'<tr><td>email Address:</td><td>'.$emailaddress.'</td></tr>'.
					'<tr><td>Response:</td><td>'.$response.'</td></tr>'.
					'<tr><td>Horse Name:</td><td>'.$horsename.'</td></tr>'.
					'<tr><td>Sire Name:</td><td>'.$sirename.'</td></tr>'.
					'<tr><td>Dam Name:</td><td>'.$damname.'</td></tr>'.
					'<tr><td>Sex:</td><td>'.$sex.'</td></tr>'.
					'<tr><td>Age:</td><td>'.$age.'</td></tr>'.
					'<tr><td>Horse:</td><td>'.$horse.'</td></tr>'.
					'<tr><td>Purchase Price:</td><td>'.$purchaseprice.'</td></tr>'.
					'<tr><td>Insure Amount:</td><td>'.$insureamount.'</td></tr>'.
					'<tr><td>Comments:</td><td>'.$comments.'</td></tr>'.
					'<tr><td>Comments:</td><td>'.$replymail.'</td></tr>'.
				'</table>';
				$message = new Message();
				$message->setCompanyId($company->getCompanyID());
				$message->setCampaignId(0);
				$message->setContactId(0);
				$message->setMesageTemplateId(0);
				$message->setMessageSubject("Request a Quote: ".$fullname);
				$message->setMessageType("EMAIL");
				$message->setMessageBilled("0");
				$message->setMessageText($disp);
				$message->setEmail_sms('[email protected]');
				$message->setMessageCost("0.23");   
				$message->setMessageDate(date('Y-m-d H:i:s'));
				$message->setStatus("QUEUED");
				$sc = $message->save();
?>
<div class="greenline"></div>
	<div id="content">
        <div id="leftcol">
		<h2><a href="index.php">Back home</a></h2>
        	<ul class="quote">
                  	<li><h1>Request a quote</h1></li>
                    <li>
                        <p>
                            Thank you <?= $full_name ?>, your request will be dealt with shortly
                        </p>
                    </li>
                </ul>  
          </div> <!--leftcol--> 
         <div id="rightcol">  
        		<ul class="forms">
                        <li><h1>Download forms</h1></li>
                        <li><h2>>> Kuda policy wording</h2><a href="KUDA POLICY WORDING.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda application Form</h2><a href="Kuda Application Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda claim form</h2><a href="Kuda Claim Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda declaration of health form</h2><a href="Kuda Declaration of Health Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Veterinary certificate</h2><a href="Kuda Veterinary Certificate.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda Pdf leaflet</h2><a href="Kuda Pdf Leaflet.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda policy - Sports horses</h2><a href="KudaPolicy Sports Horses.pdf" class="news">Download</a></li>
                    </ul>
          </div><!--rightcol-->  
       </div><!--content-->  	
       <div class="greenline"></div>  
<?php    
} else { 
?>
<script>
SendQuote = function() {
		if (document.getElementById('fullname').value=="") {
        alert ("You must enter your full name...");
        return false;
		}
		if (document.getElementById('streetaddress').value=="") {
			alert ("You must enter your email address...");
			return false;
		}  
		if (document.getElementById('city').value=="") {
        alert ("You must enter your city...");
        return false;
		}
		if (document.getElementById('postalcode').value=="") {
			alert ("You must enter your postal code...");
			return false;
		}  
		if (document.getElementById('telephone').value=="") {
        alert ("You must enter your telephone number...");
        return false;
		}
		if (document.getElementById('faxnumber').value=="") {
			alert ("You must enter your fax number...");
			return false;
		}
		if (document.getElementById('emailaddress').value=="") {
        alert ("You must enter your email address...");
        return false;
		}
		if (document.getElementById('response').value=="") {
        alert ("You must enter how you would like us to respond...");
        return false;
		}  
		if (document.getElementById('horsename').value=="") {
        alert ("You must enter your Horse name...");
        return false;
		}
		if (document.getElementById('sirename').value=="") {
			alert ("You must enter your sire name...");
			return false;
		}  
		if (document.getElementById('damname').value=="") {
        alert ("You must enter your full dam name...");
        return false;
		}
		if (document.getElementById('sex').value=="") {
			alert ("You must enter your Sex...");
			return false;
		} 
		if (document.getElementById('age').value=="") {
			alert ("You must enter your age...");
			return false;
		} 
		if (document.getElementById('horse').value=="") {
			alert ("You must enter your horse...");
			return false;
		} 
		if (document.getElementById('purchaseprice').value=="") {
			alert ("You must enter your purchase price...");
			return false;
		}
		if (document.getElementById('insureamount').value=="") {
			alert ("You must enter your insure amount...");
			return false;
		}
		if (document.getElementById('comments').value=="") {
			alert ("You must enter your comments...");
			return false;
		} 
		if (document.getElementById('replymail').value=="") {
			alert ("You must enter your reply mail...");
			return false;
		}
		document.getElementById('fullname').disabled = true;
		document.getElementById('streetaddress').disabled = true;
		document.getElementById('city').disabled = true;
		document.getElementById('postalcode').disabled = true;
		document.getElementById('telephone').disabled = true;
		document.getElementById('faxnumber').disabled = true;
		document.getElementById('emailaddress').disabled = true;
		document.getElementById('response').disabled = true;
		document.getElementById('horsename').disabled = true;
		document.getElementById('sirename').disabled = true;
		document.getElementById('damname').disabled = true;
		document.getElementById('sex').disabled = true;
		document.getElementById('age').disabled = true;
		document.getElementById('horse').disabled = true;
		document.getElementById('purchaseprice').disabled = true;
		document.getElementById('insureamount').disabled = true;
		document.getElementById('comments').disabled = true;
		document.getElementById('replymail').disabled = true;
		sent = 1;
		params = '&fullname=' + escape(document.getElementById('fullname').value);
		params += '&streetaddress=' + escape(document.getElementById('streetaddress').value);
		params += '&city=' + escape(document.getElementById('city').value);
		params += '&postalcode=' + escape(document.getElementById('postalcode').value);
		params += '&telephone=' + escape(document.getElementById('telephone').value);
		params += '&faxnumber=' + escape(document.getElementById('faxnumber').value);
		params += '&emailaddress=' + escape(document.getElementById('emailaddress').value);
		params += '&response=' + escape(document.getElementById('response').value);
		params += '&horsename=' + escape(document.getElementById('horsename').value);
		params += '&sirename=' + escape(document.getElementById('sirename').value);
		params += '&damname=' + escape(document.getElementById('damname').value);
		params += '&sex=' + escape(document.getElementById('sex').value);
		params += '&age=' + escape(document.getElementById('age').value);
		params += '&horse=' + escape(document.getElementById('horse').value);
		params += '&purchaseprice=' + escape(document.getElementById('purchaseprice').value);
		params += '&insureamount=' + escape(document.getElementById('insureamount').value);
		params += '&comments=' + escape(document.getElementById('comments').value);
		params += '&replymail=' + escape(document.getElementById('replymail').value);
		getHTML('quotations.php','function=add'+params,'bodyDiv');
} 
</script>
<div class="greenline"></div>
<div id="content">
            <div id="leftcol">
            <h2><a href="index.php">Back home</a></h2>
                <ul class="quote">
                    <li><h1>Request a quote</h1></li>
                    <li>
                        <strong>Name</strong>
                        <input name='fullname' id='fullname' size='40' class="quoteinput">
                    </li>
                    <li>
                        <strong>Street Address</strong>
                        <input name='streetaddress' id='streetaddress' size='40' class="quoteinput">
                    </li>
                    <li>
                        <strong>City</strong>
                        <input name='city' id='city' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Postal Code</strong>
                        <input name='postalcode' id='postalcode' size='8' class="quoteinput">
                    </li>
                    <li>
                        <strong>Telephone</strong>
                        <input name='telephone' id='telephone' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Fax</strong>
                        <input name='faxnumber' id='faxnumber' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Email Address</strong>
                        <input name='emailaddress' id='emailaddress' size='30' class="quoteinput">
                    </li>
                   <li>
                    <strong>How would you like to respond?</strong>
                        <table align="right">
                            <tr>
                                <td><input type='radio' name='response' id='response' value='email'><strong>Email</strong></td>
                                <td><input type='radio' id='response' name='response' value='phone'><strong>Phone </strong></td>
                                <td><input type='radio' id='response' name='response' value='fax'> <strong>Fax </strong></td>
                            </tr>
                        </table>
                     </li>
                    <li>
                        <strong>Name of the horse insured?</strong>
                        <input name='horsename' id='horsename' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Sire</strong>
                        <input name='sirename' id='sirename' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Dam</strong>
                        <input name='damname' id='damname' size='20' class="quoteinput">
                    </li>
                    <li>
                    <strong>Sex</strong>
                        <table align="right">
                            <tr>
                                <td><input type='radio' id='sex' name='sex' value='Stallion'><strong>Stallion</strong></td>
                                <td><input type='radio' id='sex' name='sex' value='Gelding'><strong>Gelding</strong></td>
                            </tr>
                        </table>
                    </li>
                    <li>
                        <strong>Age</strong>
                        <input name='age' id='age' size='3' class="quoteinput">
                    </li>
                    <li>
                        <strong>Type of horse:</strong>
                        <table align="right">
                            <tr>
                               <td><input type='radio' name='horse' id='horse' value='racing' onClick=0><strong>Racing</strong></td>
                               <td><input type='radio' id='horse' name='horse' value='breeding' onClick=0><strong>Breeding</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='showjumping' onClick=0><strong>Showjumping</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Dressage' onClick=0><strong>Dressage</strong></td>
                            </tr>
                            <tr>
                            	<td><input type='radio' name='horse' id='horse' value='Showing' onClick=0><strong>Showing</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Eventing' onClick=0><strong>Eventing</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Endurance' onClick=0><strong>Endurance</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Hacking' onClick=0><strong>Hacking</strong></td>
                            </tr>
                            <tr>
                               <td><input type='radio' name='horse' id='horse' value='Equitation' onClick=0><strong>Equitation</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Polo' onClick=0><strong>Polo</strong></td>
                               <td><input type='radio' name='horse' id='horse' value='Polocrosse' onClick=0><strong>Polocrosse</strong></td>
                             </tr>
                             <tr>
                             	<td colspan="4" align="right"><input name='horse' type='text' id='horse' onclick="0" class="quoteinput"/>&nbsp;<strong>Other</strong>&nbsp;</td>
                         
                             </tr>
                        </table>
                    </li>
                     <li>
                        <strong>Purchase price of horse:</strong>
                        <input name='purchaseprice' id='purchaseprice' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Value you would like to insure for:</strong>
                        <input name='insureamount' id='insureamount' size='20' class="quoteinput">
                    </li>
                    <li>
                        <strong>Comments or queries:</strong>
                    </li>
                    <li>
                        <textarea cols='30' rows='5' name='comments' id='comments' class="quoteinput"></textarea>
                    </li>
                    <li>
                        <strong>Would you like an email to confirm your mail?</strong>
                        <table align="right">
                            <tr>
                             <td><input type='checkbox' id='replymail' name='replymail' value='reply'></td>
                            </tr>
                        </table>
                    </li>
                    <li>
                        <input type="Button" onClick='SendQuote()' name="submit" value="" class="submitbutton">
                    </li> 
                </ul>
            </form>
           </div><!--Left Col-->
           <div id="rightcol">
                 <ul class="forms">
                        <li><h1>Download forms</h1></li>
                        <li><h2>>> Kuda policy wording</h2><a href="KUDA POLICY WORDING.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda application Form</h2><a href="Kuda Application Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda claim form</h2><a href="Kuda Claim Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda declaration of health form</h2><a href="Kuda Declaration of Health Form.pdf" class="news">Download</a></li>
                        <li><h2>>> Veterinary certificate</h2><a href="Kuda Veterinary Certificate.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda Pdf leaflet</h2><a href="Kuda Pdf Leaflet.pdf" class="news">Download</a></li>
                        <li><h2>>> Kuda policy - Sports horses</h2><a href="KudaPolicy Sports Horses.pdf" class="news">Download</a></li>
                    </ul>
               </div><!--Right Col-->
   </div><!--Content-->
   <div class="greenline"></div>
<?php
}
?>

I could not test your script since you have included several other files, however it wont work so far since you dont have a form action…

for your radio buttons they should work I don’t see anything wrong with it just remember to keep them in groups and thats what you have done so far…

example:
[php]
<input type=“radio” name="horse" value=“Black Horse”>Black Horse

<input type=“radio” name=“horse” value=“White Horse”>White Horse

<input type=“radio” name="horse" value=“Brown Horse”>Brown Horse

<input type=“radio” name=“sheep” value=“Black Horse”>Black Sheep

<input type=“radio” name="sheep" value=“Black Horse”>Black Sheep

<input type=“radio” name=“sheep” value=“Black Horse”>Black Sheep

[/php]

I also noticed you are using a global variable $_REQUEST

The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted.

I would recommend either $_GET or $_POST depending on what you would like to achieve.

Hope this helps,
Please answer me if this didn’t help or wasn’t what you where looking for.

Kind Regards,

You can scrap the [php][/php] in the example, I am new to this forum and I wasn’t aware I couldn’t use BB code in the PHP Code…

Not able to edit my previous post so excuse me for “bumping”.

Sponsor our Newsletter | Privacy Policy | Terms of Service