Solved

Help with PHP form

Posted on 2010-11-09
12
384 Views
Last Modified: 2013-12-12
Hey guys any reason why the "sport" and "shoe" fields arent returning any results
<?php

/************************
* Variables you can change
*************************/

$mailto   = "leroice@mac.com"; // Enter your mail addres here. 
$name     = ucwords($_POST['name']); 

$email    = $_POST['email'];

$sport    = $_POST['sport'];

$shoe    = $_POST['shoe'];

$message  = $_POST['message'];

	if(strlen($_POST['name']) < 1 ){
		echo  'email_error';
	}
	
  else if(strlen($email) < 1 ) {
		echo 'email_error';
	}

  else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", $email)) {
    echo 'email_error';
  }

	else if(strlen($message) < 1 ){
		echo 'email_error';

  } else {

	// NOW SEND THE ENQUIRY

	$email_message="\n\n" .
		"Name: " .
		ucwords($name) .
		"\n" .
		"Email: " .
		$email .
		"\n" .
		"Preffered Sport: " .
		$sport .
		"\n" .
		"Shoe Size: " .
		$shoe .
		"\n" .
		"Comments: " .
		"\n" .
		$message .
		"\n" .
		"\n\n" ;

		$email_message = trim(stripslashes($email_message));
		mail($mailto, $shoe, $email_message, "From: \"$vname\" <".$email.">\nReply-To: \"".ucwords($name)."\" <".$email.">\nX-Mailer: PHP/" . phpversion() );

}
?>

Open in new window

0
Comment
Question by:Leroice
  • 3
  • 2
  • 2
  • +4
12 Comments
 
LVL 5

Expert Comment

by:ploftin
ID: 34095267
You didn't include the underlying form that posts to this page, but I would suspect a problem in the form.  Verify that the fields for sport and shoe are named appropriately.  Ie.
Sport: <input type="text" name="sport" /><br />
Shoe: <input type="text" name="shoe" />

Open in new window

0
 

Author Comment

by:Leroice
ID: 34095425
Here's the markup for the form
<!-- Contact Form Start //-->
                                      <form action="#" id="contactform"> 
                                      <fieldset>
                                      <label>Name*</label>
                                      <input type="text" name="name" class="textfield" id="name" value="Please enter both given and surnames" />
                                      <div class="clear"></div>
                                      <label>E-mail*</label>
                                      <input type="text" name="email" class="textfield" id="email" value="Please enter a valid email address" />
                                      <div class="clear"></div> 
                                      <label>Prefered Sport*</label>
                                      <input type="text" name="subject" class="textfield" id="sport" value="Enter your Favourite Sport here" />
                                      <div class="clear"></div> 
                                      <label>Shoe Size*</label>
                                      <input type="text" name="subject" class="textfield" id="shoe" value="Please indicate Men's or Women's sizing" />
                                      <div class="clear"></div>    
                                      <label>Message*</label>
                                      <textarea name="message" id="message" class="textarea" cols="2" rows="7" </textarea>
                                      <div class="clear"></div> 
                                                                      <input type="submit" name="submit" class="buttoncontact" id="buttonsend" value="Send" />
                                      <span class="loading" style="display: none;">Please wait..</span>
                                      <div class="clear"></div>
                                      <label>&nbsp;</label>
                                      *required field
                                      <div class="clear"></div>
                                      </fieldset> 
                                      </form>
                                      <!-- Contact Form End //--> 

Open in new window

0
 
LVL 5

Accepted Solution

by:
ploftin earned 500 total points
ID: 34095586
That's your problem.  Your shoe and sport fields need to be "named" shoe and sport.  For example, change your form to this:
<!-- Contact Form Start //-->
<form action="#" id="contactform"> 
<fieldset>
<label>Name*</label>
<input type="text" name="name" class="textfield" id="name" value="Please enter both given and surnames" />
<div class="clear"></div>
<label>E-mail*</label>
<input type="text" name="email" class="textfield" id="email" value="Please enter a valid email address" />
<div class="clear"></div> 
<label>Prefered Sport*</label>
<input type="text" name="sport" class="textfield" id="sport" value="Enter your Favourite Sport here" />
<div class="clear"></div> 
<label>Shoe Size*</label>
<input type="text" name="shoe" class="textfield" id="shoe" value="Please indicate Men's or Women's sizing" />
<div class="clear"></div>    
<label>Message*</label>
<textarea name="message" id="message" class="textarea" cols="2" rows="7" </textarea>
<div class="clear"></div> 
                                <input type="submit" name="submit" class="buttoncontact" id="buttonsend" value="Send" />
<span class="loading" style="display: none;">Please wait..</span>
<div class="clear"></div>
<label>&nbsp;</label>
*required field
<div class="clear"></div>
</fieldset> 
</form>
<!-- Contact Form End //--> 

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Expert Comment

by:Mark Brady
ID: 34099829
You named both the sports and the shoe fields "subject" that's why nothing is posted for those two fields.
0
 
LVL 1

Expert Comment

by:djshah
ID: 34103826
+++++
<input type="text" name="subject" class="textfield" id="sport" value="Enter your Favourite Sport here" />
                                      <div class="clear"></div>
                                      <label>Shoe Size*</label>
                                      <input type="text" name="subject" class="textfield" id="shoe" value="Please indicate Men's or Women's sizing" />
                                      <div class="clear"></div>  
+++++

Just change above code with following code:

++++
<input type="text" name="sport" class="textfield" id="sport" value="Enter your Favourite Sport here" />
                                      <div class="clear"></div>
                                      <label>Shoe Size*</label>
                                      <input type="text" name="shoe" class="textfield" id="shoe" value="Please indicate Men's or Women's sizing" />
                                      <div class="clear"></div>  
++++

It should then work. You have given name="subject" for both id="sport" and id="shoe". When form is submitted in php _POST array is build on name attribute. If name is not properly given then it will not be there in _POST array.
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34125023
Any reply from the asker?
0
 
LVL 20

Expert Comment

by:Mark Brady
ID: 34128644
Hey Leroice:     Did you change your form to what we said and try it? Please let us know so we can all move on and get this question PAQ'ed

Cheers
Elvin
0
 

Author Comment

by:Leroice
ID: 34129334
Sorry guys haven't been online for past few days. Will have a try and let you know soon.

Thanks again for the help. It is much appreciated
0
 
LVL 13

Expert Comment

by:p_nuts
ID: 34214845
I think the rest helped you with this one.. but a general tip..

use

print_r($_REQUEST);

to see all submitted variables to test....
0
 

Expert Comment

by:sridharphp
ID: 34514026
try to write like this
if(isset($_post['submit']))
{
$comapny_name=$_POST['company_name'];//like this all  fields create
$sql="insert into tbl_users (company_name, first_name, last_name, business_street_address, business_suburb_city, business_postcode, email, phone, mobile, industry_id , username,password) values('$company_name', '$first_name', '$last_name', '$business_street_address', '$business_suburb_city', '$business_postcode', '$email', '$phone', '$mobile', '$industry', '$username','$password')";
mysql_query($sql);
header('location:samepage.php')
exit;
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 35390505
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question