Log in

View Full Version : form problem



Chadi
12-14-2007, 06:16 PM
I have this quote form I setup, general basic fields. The problem is the form sends only this to the email recipient (my end). It does not include all the info of all fields. I'm not a programmer, so help is appreciated.

The only thing shown in the email is this:

Name:

Email Address:

Subject:

Message:


process.php


<?php
@extract($_POST);

$messageText = 'Name: ' . stripslashes($user_name) . "\r\n";
$messageText .= 'Email Address: ' . stripslashes($email_address) . "\r\n";
$messageText .= 'Subject: ' . stripslashes($subject) . "\r\n";
$messageText .= 'Message: ' . stripslashes($message) . "\r\n";

$to = 'sales@mydomain.com';
$subject = 'Website Contact Form Submission';
$message = $messageText;
$headers = 'From: Form Mailer <sales@mydomain.com>';

mail($to, $subject, $message, $headers);

?>

Chadi
12-14-2007, 06:16 PM
the form


<form method="post" action="process.php">
<table>
<tr>
<td class="style5" colspan="2" style="height: 25px"><strong>Contact</strong></td>
<td class="style5" colspan="2" style="height: 25px"><strong>Location</strong></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;"><label for="name">Name</label></td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="First_Name" type="text" /></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Last Name</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Last_Name" type="text" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">City</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="City" type="text" /></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">State</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="State" type="text" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Phone</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Phone" type="text" /></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Country</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Country" type="text" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Email</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Email" type="text" /></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Company</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Company" type="text" /></td>
</tr>
<tr>
<td class="style5" colspan="2" style="height: 25px"><strong>Requirements</strong></td>
<td class="style5" colspan="2" style="height: 25px">&nbsp;</td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Processor</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Processor">
<option></option>
<option>*** Intel ***</option>
<option>Celeron</option>
<option>Pentium IV HT</option>
<option>Dual Core Xeon</option>
<option>Quad Core Xeon</option>
<option>*** AMD ***</option>
<option>Dual Core Opteron</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Second
Processor</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Second_Process" type="checkbox" value="Second_Process" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Memory</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Memory">
<option></option>
<option>512MB</option>
<option>1GB</option>
<option>2GB</option>
<option>4GB</option>
<option>8GB</option>
<option>12GB</option>
<option>16GB</option>
<option>More than 16GB</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Disk Drives</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Disks">
<option></option>
<option>*** SATA ***</option>
<option>160GB</option>
<option>2x160GB</option>
<option>1x250GB</option>
<option>2x250GB</option>
<option>1x500GB</option>
<option>2x500GB</option>
<option>1x1TeraByte</option>
<option>2x1TeraByte</option>
<option>*** SCSI ***</option>
<option>1x36GB</option>
<option>2x36GB</option>
<option>1x73GB</option>
<option>2x73GB</option>
<option>1x146GB</option>
<option>2x146GB</option>
<option>1x300GB</option>
<option>2x300GB</option>
<option>1x400GB</option>
<option>2x400GB</option>
</select></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Quantity of
Servers</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Quantity">
<option></option>
<option>1</option>
<option>2</option>
<option>3-5</option>
<option>6-12</option>
<option>12 or more</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">RAID</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="RAID">
<option></option>
<option>None</option>
<option>Raid 0</option>
<option>Raid 1</option>
<option>Raid 3</option>
<option>Raid 5</option>
</select></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">IP Address</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="IP_Address0">
<option></option>
<option>8</option>
<option>16</option>
<option>32</option>
<option>64</option>
<option>Half C Class (128)</option>
<option>C Class (256)</option>
<option>Multiple C Class</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Port</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Port0">
<option></option>
<option>100MBps</option>
<option>Dual 100MBps</option>
<option>1GBps</option>
<option>Dual 1GBps</option>
<option>Other</option>
</select></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">
Operating System</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Operating_System">
<option></option>
<option>*** Linux ***</option>
<option>Centos</option>
<option>Debian</option>
<option>Fedora</option>
<option>Free BSD</option>
<option>Gentoo</option>
<option>Redhat Enterprise</option>
<option>Ubuntu Server</option>
<option>*** Windows ***</option>
<option>Windows Server 2003</option>
<option>Windows Server 2008</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">
Control Panel</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<select name="Control_Panel">
<option></option>
<option>Cpanel / WHM</option>
<option>Interworx</option>
<option>Helm</option>
<option>Plesk</option>
<option>Webmin</option>
</select></td>
</tr>
<tr>
<td class="style5" colspan="2" style="height: 25px"><strong>Optional
Services</strong></td>
<td class="style5" colspan="2" style="height: 25px">&nbsp;</td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Server
Management</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Management" type="checkbox" value="Management" /></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Remote Reboot</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Remote_Reboot" type="checkbox" value="Remote_Reboot" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Clustering</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="Clustering" type="checkbox" value="Clustering" />&nbsp;</td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">NAS
Backups</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;">
<input name="NAS" type="checkbox" value="NAS" /></td>
</tr>
<tr>
<td class="style8" style="text-align:left; width: 142px; height: 25px;">Phase</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;"><select name="Mode">
<option></option>
<option>Actively Shopping</option>
<option>Budgetary Numbers</option>
<option>Researching</option>
</select></td>
<td class="style8" style="text-align:left; width: 136px; height: 25px;">Criteria</td>
<td class="style8" style="text-align:left; width: 140px; height: 25px;"><select name="Criteria">
<option></option>
<option>Budgetary</option>
<option>Location</option>
<option>Provisioning Time</option>
<option>SLA</option>
</select></td>
</tr>
<tr>
<td class="style4" colspan="4">Message<br />
<textarea name="Message" cols="50" rows="4"></textarea>&nbsp;</td>
</tr>
</table>
<input name="Submit1" type="submit" value="submit" />
</form>

smithster
12-14-2007, 06:22 PM
You haven't actually posted any of the information from the form to the PHP page.

Here's what you are missing from your php script...



$First_Name = $_POST['First_Name'];
$Last_Name = $_POST['Last_Name'];
and so on.....

Just repeat the same process for each piece of information you are posting. Whatever the field is called, first one input name = "First_Name", that's what needs to be posted.

Hope this helps.

Smithster.

Jas
12-14-2007, 06:24 PM
There is a faster way. Try

Extract($_POST, EXTR_PREFIX_SAME, "POST");
It will get all of that for you. I used to do it long hand as well, until I found this :)

smithster
12-14-2007, 06:29 PM
wow! I have never seen that before?!?!? Can you include security in that statement though with it pulling everything from the form in one go?

Jas
12-14-2007, 06:33 PM
wow! I have never seen that before?!?!? Can you include security in that statement though with it pulling everything from the form in one go?

Perhaps. I haven't tried too hard. One of these days I'll have to check. Maybe:

strip_tags(Extract($_POST, EXTR_PREFIX_SAME, "POST"));
(Again, I don't know if that works or not. . .)

Jas
12-15-2007, 04:53 AM
I don't see those fields anywhere in your form Chadi. Are you sure the info is coming in?

djr33
12-15-2007, 05:07 AM
Why use extract? That's just bad practice.

Use $_POST['field_name'] to get any value.

Jas
12-15-2007, 07:29 PM
How is it bad practice? In certain senarios I think it's advantageous. And, I really don't see the difference in the outcome. Both use the same amount of vars, but one takes less time and space.

thetestingsite
12-15-2007, 07:36 PM
Extract is almost like using register_globals, if you use extract at the top of your php script; then later on use a variable of the same name it will overwrite the first value of that same variable. Example:



//extract and other code here

echo $first_name;

//more code here

$first_name = $_GET['something'];

echo $first_name;

//more code


Probably not the best example, but you get the idea.
Hope this helps.

Jas
12-15-2007, 07:49 PM
I do see your point theTestingSite, but I still think it's advantageous. If you are only using the information for a short amount of time, and you have lots of it-- which appears to be the case in this script-- I don't see the problem. What's the difference in that and $var = $_POST['var'] ? Extract doesn't actually make them global does it?

thetestingsite
12-15-2007, 07:57 PM
If you look at the documentation on php.net (http://php.net/extract), you can see that it in fact does make it a "global" variable for the script/page that you send the data to.

Hope this helps.

Twey
12-15-2007, 08:02 PM
Yes, it does make them global. Cluttering up the global namespace is always a bad idea, in any language. Generally you should try to have only necessary entry points in the global namespace. PHP's scoping system is pants, so there are quite a few cases in which it's necessary to make more global variables than should strictly be needed, but still you should avoid doing so where possible.

Jas
12-15-2007, 08:20 PM
Thanks guys. I see the problem now. But, is there a way to do the same thing without global vars?