Jump to content

Please help - new to PHP


dmreid

Recommended Posts

Hi, I have created a form with radio buttons I believe I have not coded it correctly in the php.  I wasn't sure of the proper php code for the radio as opposed to the text buttons.

 

Please take a look, thanks! 

 

I have attached both the sportsform and the send_form_email.php.

 

I really appreciate your help in advance!!!!!

 

D

 

 

 

 

send_form_email.php

sportsform.php

Link to comment
Share on other sites

Your use of radio buttons is incorrect.

 

Radio buttons are used for listing a group of options, but only one option can be selected from that group. To define a group of options each radio button should be named the same and have a unique value.

 

The problem is you have given all radio buttons their own unique name. For example for choosing the baseball category you have named each radio button uniquely as baseball_type. The radio button name should just be set to baseball, but the type should be the value. 

<input type="radio" name="baseball" value="tball"/>
<input type="radio" name="baseball" value="rookie"/>
<input type="radio" name="baseball" value="mosquito"/ >
<input type="radio" name="baseball" value="peewee"/>
<input type="radio" name="baseball" value="bantam"/ >

When the form is submitted $_POST['baseball'] will contain the chosen option. However if no option was selected then $_POST['baseball'] will not exist when the form is submitted.

 

What you need to do is go through your HTML and set each group of options to the same name.

Edited by Ch0cu3r
Link to comment
Share on other sites

Thank you so much Ch0cu3r, I can't tell you enough how much I appreciate your help!

 

That makes so much sense.  So what is the proper code to ensure that a radio button is filled in, for example, for them to acknowledge a waiver?

 

Thanks again for all your help!

D

Link to comment
Share on other sites

<?php
 
if(isset($_POST['email'])) {
 
     
 
    // EDIT THE 2 LINES BELOW AS REQUIRED
 
    $email_to = "info@davisburg.ca";
 
    $email_subject = "Davisburg Sports Registration";
 
    function died($error) {
 
        // your error code can go here
 
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
 
        echo "These errors appear below.<br /><br />";
 
        echo $error."<br /><br />";
 
        echo "Please go back and fix these errors.<br /><br />";
 
        die();
 
    }
 
     
 
    // validation expected data exists
 
    if(!isset($_POST['players_first_name']) ||
 
        !isset($_POST['players_last_name']) ||
		
		!isset($_POST['players_birth']) ||
		
		!isset($_POST['soccer']) ||
		!isset($_POST['baseball']) ||
		
		
		!isset($_POST['parentnames']) ||
		
        !isset($_POST['email']) ||
        !isset($_POST['telephone']) ||
		
		!isset($_POST['mother_cell']) ||
		!isset($_POST['father_cell']) ||
		!isset($_POST['t_shirt']) ||
		!isset($_POST['volunteer']) ||
		
		!isset($_POST['comments']) ||
		!isset($_POST['waivername']) ||
		!isset($_POST['waiveraddress']) ||
		!isset($_POST['waiverphone']) ||
		!isset($_POST['waiver']) ||
		!isset($_POST['waiverdate'])) {
	
 
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
 
    }
 
     
 
    $players_first_name = $_POST['players_first_name']; // not required
 
    $players_last_name = $_POST['players_last_name']; // not required
	
	$players_birth = $_POST['players_birth']; // not required
			
	$parentnames = $_POST['parentnames']; // not required
	$email_from = $_POST['email']; // required
 
    $telephone = $_POST['telephone']; // not required
	$mother_cell = $_POST['mother_cell']; // not required
	$father_cell = $_POST['father_cell']; // not required
	
	$comments = $_POST['comments']; // not required
	$waivername = $_POST['waivername']; // not required
	$waiveraddress = $_POST['waiveraddress']; // not required
	$waiverphone = $_POST['waiverphone']; // not required
	$waiver = $_POST['waiver']; // not required
	$waiverdate = $_POST['waiverdate']; // not required
	
     
    $error_message = "";
 
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
 
  if(!preg_match($email_exp,$email_from)) {
 
    $error_message .= 'Please fill in a valid email address.<br />';
 
  }
 
 
 
  if(strlen($error_message) > 0) {
 
    died($error_message);
 
  }
 
    $email_message = "Form details below.\n\n";
 
     
 
    function clean_string($string) {
 
      $bad = array("content-type","bcc:","to:","cc:","href");
 
      return str_replace($bad,"",$string);
 
    }
    $email_message .= "Players First Name: ".clean_string($players_first_name)."\n";
	$email_message .= "Players Last Name: ".clean_string($players_last_name)."\n";
	$email_message .= "Players Birthdate: ".clean_string($players_birth)."\n";
	$email_message .= "Soccer: ".clean_string($soccer)."\n";
	$email_message .= "Baseball: ".clean_string($baseball)."\n";
	
	$email_message .= "Parent's Names: ".clean_string($parentnames)."\n";
	$email_message .= "Home Telephone: ".clean_string($telephone)."\n";
	$email_message .= "Mother's Cell: ".clean_string($mother_cell)."\n";
	$email_message .= "Fathers's Cell: ".clean_string($father_cell)."\n";
	$email_message .= "T-Shirt:".clean_string($t_shirt)."\n";
	
				$email_message .= "Volunteer: ".clean_string($volunteer)."\n";
				$email_message .= "Comments: ".clean_string($comments)."\n";
				$email_message .= "Waiver Name: ".clean_string($waivername)."\n";
				$email_message .= "Waive Address: ".clean_string($waiveraddress)."\n";
				$email_message .= "Waiver Phone: ".clean_string($waiverphone)."\n";
				$email_message .= "Waiver: ".clean_string($waiver)."\n";
				$email_message .= "Waiver Date: ".clean_string($waiverdate)."\n";
	    
 
     
 
// create email headers
 
$headers = 'From: '.$email_from."\r\n".
 
'Reply-To: '.$email_from."\r\n" .
 
'X-Mailer: PHP/' . phpversion();
 
@mail($email_to, $email_subject, $email_message, $headers);  
 
?>
 
 
 
<!-- include your own success html here -->
 
 
 
Your Registration was successfully received, thank you!<br /><br />

<br /><br />

Please make payment: <br /><br />

   

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="info@davisburg.ca">
<input type="hidden" name="lc" value="CA">
<input type="hidden" name="item_name" value="SODBUSTER SPORTS">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
<table>
<tr><td><input type="hidden" name="on0" value="SODBUSTER SPORTS">SODBUSTER SPORTS</td></tr><tr><td><select name="os0">
	<option value="Soccer">Soccer $40.00 CAD</option>
	<option value="T-Ball">T-Ball $50.00 CAD</option>
	<option value="Soccer + T-ball  w T-Shirt">Soccer + T-ball  w T-Shirt $75.00 CAD</option>
	<option value="Rookie, Mosquito, Peewee & Bantam">Rookie, Mosquito, Peewee & Bantam $90.00 CAD</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="CAD">
<input type="hidden" name="option_select0" value="Soccer">
<input type="hidden" name="option_amount0" value="40.00">
<input type="hidden" name="option_select1" value="T-Ball">
<input type="hidden" name="option_amount1" value="50.00">
<input type="hidden" name="option_select2" value="Soccer + T-ball  w T-Shirt">
<input type="hidden" name="option_amount2" value="75.00">
<input type="hidden" name="option_select3" value="Rookie, Mosquito, Peewee & Bantam">
<input type="hidden" name="option_amount3" value="90.00">
<input type="hidden" name="option_index" value="0">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>


<?php
 
}
 
?>

I still can't get it continuously working, sometimes it does, then doesn't so there has to be an issue in it somewhere:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.