PHP Form Help

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
derbra1513
Forum Newbie
Posts: 5
Joined: Wed Sep 08, 2010 1:31 am

PHP Form Help

Post by derbra1513 »

I was hoping someone could help me out with my php form, I have 2 on my site one to request a quote (doesnt work) and on basic contact form (this one works). The quote form is not working because I tried to add more sections to it and I was trying to play with it to no avail. Here is the code and if anyone can send me to a good tutorial or help with code I would appreciate it.

Code: Select all

<?php
// Contact subject
$subject ="$subject"; 
// Details
$message="
Name: $name\n 
Company: $company\n
City/State: $city\n
Phone: $phone\n
Email: $customer_mail\n
Services Company Provides:\n
$products, $services, $charity\n
Website: $web\n
Services Needed:\n
$id\n, $bcd\n, $pd\n, $mm\n, $wd\n, $ec\n, $cms\n, $seo\n, $other\n, $otherservice\n
Project Description: $projdesc\n
Project Budget:$money\n
Additional Info: $add\n";

// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name <$mail_from>";

// Enter your email address
$to ='derrickworkman@gmail.com';

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
And here is the HTML

Code: Select all

<form name="form1" method="post" action="send_request.php" class="paragraph_main">
Contact Info
          <fieldset>
            <p>
              <label for="dummy0">Your Name:</label><br>
              <input type="text" class="text" name="nameone" id="nameone" value="First, Last">
            </p>

            <p>
              <label for="dummy1">Company:</label><br>
              <input type="text" class="text" id="name" name="name" value="Company Name">
            </p>
            
             <p>
              <label for="dummy2">City and State:</label><br>
              <input type="text" class="text" id="city" name="city" value="City, State">
            </p>
           
			 <p>
              <label for="dummy3">Phone:</label><br>
              <input type="text" class="text" id="phone" name="phone" value="Phone">
            </p>
              <p>
              <label for="dummy4">E-Mail:</label><br>
              <input type="text" class="text" id="customer_mail" name="customer_mail" value="Email Address">
            </p>
      </fieldset>
      Company Info
          <fieldset>
            <p>
              <label for="dummy5"><b>Services You Provide:</b></label><br>
            <input type="checkbox" id="products" name="products" class="moveup2"> Products&nbsp;&nbsp;&nbsp;
            <input type="checkbox" id="services" name="services" class="moveup2"> Services&nbsp;&nbsp;&nbsp;
            <input type="checkbox" id="charity" name="charity" class="moveup2"> Charity
            </p>

            <p>
              <label for="dummy6"><b>Business Description:</b></label><br>
              <textarea id="businessdesc" name="businessdesc" rows="8" cols="25" ></textarea>
            </p>
            
             <p>
              <label for="dummy7"><b>Current Website URL:</b> </label><br>
              <input type="text" class="text" id="web" name="web" value="Leave Blank If You Do Not Have A Website">
            </p>
      </fieldset>
      Project Details
          <fieldset>
            <p>
              <label for="dummy8"><b>Services Needed:</b></label><br>
            <input type="checkbox" id="ld" name="id" class="moveup2"> Logo Design<br />
            <input type="checkbox" id="bcd" name="bcd" class="moveup2"> Business Card Design<br />
            <input type="checkbox" id="pd" name="pd" class="moveup2"> Print Design<br /> 
            <input type="checkbox" id="mm" name="mm" class="moveup2"> Marketing Material<br />            
            <input type="checkbox" id="wd" name="wd" class="moveup2"> Website Design<br />
            <input type="checkbox" id="ec" name="ec" class="moveup2"> Website With Shopping Cart<br />
            <input type="checkbox" id="cms" name="cms" class="moveup2"> CMS Website<br />
            <input type="checkbox" id="seo" name="seo" class="moveup2"> SEO Opimization<br />
            <input type="checkbox" id="other" name="other" class="moveup2"> Other: Specify Below<br />
            <input type="text" class="text" id="otherservice" name="otherservice" value="Please List Any Other Services Needed:">


            </p>

            <p>
              <label for="dummy9"><b>Project Description:</b></label>
              <br>
              <textarea id="projdesc" name="projdesc" rows="8" cols="25"></textarea>
            </p>
            
             <p>
              <label for="dummy10">Project Budget:</label><br>
            <select id="money" name="money">
              <option value="1" >$300 - $600</option>
              <option value="2" >$600 - $800</option>
              <option value="3">$800 - $1000</option>
              <option value="4">$1000 - $1500</option>
              <option value="5" >$1500 - $2000</option>
              <option value="6" >$2000 - $3000</option>
              <option value="7" >$3000 - $4000</option>
            </select>         
            </p>
           
              <p>
              <label for="dummy11"><b>Additional Information:</b></label>
              <br>
              <textarea id="add" name="add" rows="8" cols="25"></textarea>
            </p>
            </p>
      </fieldset>
        
                    <p>
              <input type="submit" name="Submit" value="Submit">
              <input type="reset"  name="Submit2" value="Reset">
            </p>
        </form>
Thanks again for all your help!
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Form Help

Post by highjo »

Hi !
What exactly doesn't work? the processing of the form or the sending of email?
derbra1513
Forum Newbie
Posts: 5
Joined: Wed Sep 08, 2010 1:31 am

Re: PHP Form Help

Post by derbra1513 »

email sends ok and I recieve it but it all comes in blank. Only the $name field comes in with my name and the email that you fill out, evrything else is blank
User avatar
highjo
Forum Contributor
Posts: 118
Joined: Tue Oct 24, 2006 1:07 pm

Re: PHP Form Help

Post by highjo »

i assume then that send_request.php is the script that process the form's data right? you defined you form as using the post method.
but i cannot see any post "super global" variable in your code.so what i suggest is to see what is happening.comment out every thing between the php tags and add this:

Code: Select all

<?php 
//....
// all you commented

//so if you are using xdebug do this
var_dump($_POST);

//but if you are not using xdebug or don't know what it is do this
echo "<pre>";
print_r($_POST);
echo "</pre>";
 
?>


hope this will help you find what's happening
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Form Help

Post by califdon »

The PHP code you showed us doesn't define any of those variables (like $name, $company, etc.), so it's not surprising that nothing is passed to the email. Either you haven't showed us the part of your code where the problem is or you are missing the most important part of the code.
derbra1513
Forum Newbie
Posts: 5
Joined: Wed Sep 08, 2010 1:31 am

Re: PHP Form Help

Post by derbra1513 »

Ok so I am a complete noob when it comes to PHP but I did a lot of reading this afternoon and changed my code a little. Does this look like there are any errors in my PHP?

The only problem I am having now is getting the drop down menu to show up in my email with the actual data ex. $300-$600, $600-$800. All that shows up is the number of the element ex. 1, 2, 3 etc.

Code: Select all

<?php
// Contact subject
$subject ="$subject"; 
// Details
$phone = $_POST["phone"];
$company = $_POST["company"];
$city = $_POST["city"];
$name = $_POST["name"];
$customer_email = $_POST["customer_email"];
$web = $_POST["web"];
$projdesc = $_POST["projdesc"];
$money = $_POST["money"];
$add = $_POST["add"];
$otherservice = $_POST["otherservice"];


$message="Name: $name\n
Company: $company\n
City/State: $city\n
Phone: $phone\n
Email: $customer_mail\n
Services Company Provides:\n
Products: $products, Services: $services, Charity: $charity\n
Website: $web\n
Services Needed:\n
Logo Design: $id\n, Business Card Design: $bcd\n, Print Design: $pd\n,Marketing Material: $mm\n,Website Design: $wd\n,E-Commerce: $ec\n,CMS Website: $cms\n,SEO: $seo\n,Other: $other\n,Other Service: $otherservice\n
Project Description: $projdesc\n
Project Budget:$money\n
Additional Info: $add\n";
// Mail of sender
$mail_from="$customer_mail"; 
// From 
$header="from: $name <$mail_from>";

// Enter your email address
$to ='derrickworkman@gmail.com';

$send_contact=mail($to,$subject,$message,$header);

// Check, if message sent to your email 
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
And the HTML

Code: Select all

<form name="form1" method="post" action="send_request.php" class="paragraph_main">
Contact Info
          <fieldset>
            <p>
              <label for="dummy0">Your Name:</label><br>
              <input type="text" class="text" name="name" id="name" value="First, Last">
            </p>

            <p>
              <label for="dummy1">Company:</label><br>
              <input type="text" class="text" id="company" name="company" value="Company Name">
            </p>
            
             <p>
              <label for="dummy2">City and State:</label><br>
              <input type="text" class="text" id="city" name="city" value="City, State">
            </p>
           
			 <p>
              <label for="dummy3">Phone:</label><br>
              <input type="text" class="text" id="phone" name="phone" value="Phone">
            </p>
              <p>
              <label for="dummy4">E-Mail:</label><br>
              <input type="text" class="text" id="customer_mail" name="customer_mail" value="Email Address">
            </p>
      </fieldset>
      Company Info
          <fieldset>
            <p>
              <label for="dummy5"><b>Services You Provide:</b></label><br>
            <input type="checkbox" id="products" name="products" class="moveup2"> Products&nbsp;&nbsp;&nbsp;
            <input type="checkbox" id="services" name="services" class="moveup2"> Services&nbsp;&nbsp;&nbsp;
            <input type="checkbox" id="charity" name="charity" class="moveup2"> Charity
            </p>

            <p>
              <label for="dummy6"><b>Business Description:</b></label><br>
              <textarea id="businessdesc" name="businessdesc" rows="8" cols="25" ></textarea>
            </p>
            
             <p>
              <label for="dummy7"><b>Current Website URL:</b> </label><br>
              <input type="text" class="text" id="web" name="web" value="Leave Blank If You Do Not Have A Website">
            </p>
      </fieldset>
      Project Details
          <fieldset>
            <p>
              <label for="dummy8"><b>Services Needed:</b></label><br>
            <input type="checkbox" id="ld" name="id" class="moveup2"> Logo Design<br />
            <input type="checkbox" id="bcd" name="bcd" class="moveup2"> Business Card Design<br />
            <input type="checkbox" id="pd" name="pd" class="moveup2"> Print Design<br /> 
            <input type="checkbox" id="mm" name="mm" class="moveup2"> Marketing Material<br />            
            <input type="checkbox" id="wd" name="wd" class="moveup2"> Website Design<br />
            <input type="checkbox" id="ec" name="ec" class="moveup2"> Website With Shopping Cart<br />
            <input type="checkbox" id="cms" name="cms" class="moveup2"> CMS Website<br />
            <input type="checkbox" id="seo" name="seo" class="moveup2"> SEO Opimization<br />
            <input type="checkbox" id="other" name="other" class="moveup2"> Other: Specify Below<br />
            <input type="text" class="text" id="otherservice" name="otherservice" value="Please List Any Other Services Needed:">


            </p>

            <p>
              <label for="dummy9"><b>Project Description:</b></label>
              <br>
              <textarea id="projdesc" name="projdesc" rows="8" cols="25"></textarea>
            </p>
            
             <p>
  <label for="dummy10">Project Budget:</label><br>
              <select id="money" name="money">
              <option  value="$300-$600">$300 - $600</option>
              <option value="2">$600 - $800</option>
              <option value="3">$800 - $1000</option>
              <option value="4">$1000 - $1500</option>
              <option value="5" >$1500 - $2000</option>
              <option value="6" >$2000 - $3000</option>
              <option value="7" >$3000 - $4000</option>
            </select>  
            </p>
           
              <p>
              <label for="dummy11"><b>Additional Information:</b></label>
              <br>
              <textarea id="add" name="add" rows="8" cols="25"></textarea>
            </p>
            </p>
      </fieldset>
        
                    <p>
              <input type="submit" name="Submit" value="Submit">
              <input type="reset"  name="Submit2" value="Reset">
            </p>
        </form>
Once again guys thanks for all the help, and just to clarify I bolded the section I am having some trouble with.

<label for="dummy10">Project Budget:</label><br>
<select id="money" name="money">
<option value="$300-$600">$300 - $600</option>
<option value="2">$600 - $800</option>
<option value="3">$800 - $1000</option>
<option value="4">$1000 - $1500</option>
<option value="5" >$1500 - $2000</option>
<option value="6" >$2000 - $3000</option>
<option value="7" >$3000 - $4000</option>
</select>
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Form Help

Post by califdon »

Yes, you're getting close now. Here's how a <select> element (dropdown box) works: each <option> element has 2 parts, one inside the <option> tag and one between the <option> and </option> tags. The second one, between the tags, is what the user sees in the dropdown list (it is NOT the value that is returned when the option is selected). The first one, inside the tag, is like it says, the value that is returned. What you are seeing (1, 2, 3, etc.) is NOT the number of the element, it is simply what you have told it send as the value when that option is selected. You can change those value= parts to be whatever you want to be returned, like "$300 - $600".
derbra1513
Forum Newbie
Posts: 5
Joined: Wed Sep 08, 2010 1:31 am

Re: PHP Form Help

Post by derbra1513 »

Awesome! Thanks for all the help.

The form is working now you can check it out here if you want.

http://boonmultimediadesign.com/newsite ... quote.html
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Form Help

Post by califdon »

I'm glad it's working for you. That's a nice looking page (adorable kid!!), but your wording needs to be spell checked. I found 2 misspellings in one sentence, near the top.
Post Reply