Go Back  HTML Forums - Free Webmaster Forums and Help Forums > WEBSITE DEVELOPMENT > Server Side Programming > PHP Programming
User Name:
Password:
 

Reply
Thread Tools   Display Modes
  View First Unread
 
Old 02-03-2012, 08:06 PM
  #1
chartkor
Novice (Level 1)
 
Join Date: Jan 2012
Posts: 5
iTrader: (0)
chartkor is an unknown quantity at this point
Smile Complex Email form (PHP)

Hello,
on my website I have a complex Email form, can be found here:
http://cleaningcrazy.com/contactus.html

Now unfortunately I tried but I can't get it to work properly. I found a working php script which I cut to my needs a little, however it only provides support for 3 fields. This is how it looks like:
PHP Code:
<?php
$field_name 
$_POST['cf_name'];
$field_email $_POST['cf_email'];
$field_message $_POST['cf_message'];

$mail_to 'info@cleaningcrazy.com';
$subject 'Customer '.$field_name;

$body_message 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status mail($mail_to$subject$body_message$headers);

if (
$mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contactus.html';
    </script>
<?php
}
else { 
?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to info@cleaningcrazy.com');
        window.location = 'contactus.html';
    </script>
<?php
}
?>
Now I tried adding more $field parameters in order to get it to work, but it still doesn't.
This is the first time I have something to do with PHP, so please explain in a very simplistic manner.
chartkor is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 02-04-2012, 09:53 AM
  #2
scoutt
Mister Admin to you
 
scoutt's Avatar
 
Join Date: Jul 2001
Posts: 31,994
iTrader: (0)
scoutt is just really nicescoutt is just really nicescoutt is just really nicescoutt is just really nicescoutt is just really nice
for each field on the contact form you have to use the php equivalent, thats the $_POST part. The 'cf_name' is the name of the input field you want to capture.
PHP Code:
$field_name $_POST['cf_name'];
$field_email $_POST['cf_email'];
$field_message $_POST['cf_message']; 
But I see you have four cf_message as your zipcode, phone and cleaning fields should be something ldifferent, like cf_zipcode for th epostal code field, then just add it to the php code


PHP Code:
$field_name $_POST['cf_name'];
$field_email $_POST['cf_email'];
$field_message $_POST['cf_message'];
$field_zipcode $_POST['cf_zipcode'];

$body_message 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Postal Code: '.$field_zipcode."\n"
$body_message .= 'Message: '.$field_message
Not only do you have to do it correct in php you have to know what you are doing in html. But you should see what you need to do to add the others, as they also have cf_message as the name, which you can only one one. Make sense?
__________________
Have a Script or Snippet you want to share?

WWW Standards: HTML 4.01,
HTML 5, CSS2.1, CSS3, XHTML 1.0
PHP Standards: PHP Standards
scoutt is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 02-04-2012, 10:25 AM
  #3
chartkor
Novice (Level 1)
 
Join Date: Jan 2012
Posts: 5
iTrader: (0)
chartkor is an unknown quantity at this point
Thank you very much, it helped, but partially, or I am still doing something wrong.
This is the code right now
PHP Code:
<?php
$field_name 
$_POST['cf_name'];
$field_email $_POST['cf_email'];
$field_postalcode $_POST['cf_postalcode'];
$field_telephone $_POST['cf_telephone'];
$field_service $_POST['cf_service'];
$field_frequency $_POST['cf_frequency'];
$field_message $_POST['cf_message'];


$mail_to 'info@cleaningcrazy.com';
$subject 'Customer '.$field_name;

$body_message 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Postal Code: '.$field_postalcode."\n";
$body_message .= 'Telephone: '.$field_telephone."\n";  
$body_message .= 'Service Type: '.$field_service."\n"
$body_message .= 'Frequency: '.$field_frequency."\n"
$body_message .= 'Message: '.$field_message;

$headers 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status mail($mail_to$subject$body_message$headers);

if (
$mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contactus.html';
    </script>
<?php
}
else { 
?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to info@cleaningcrazy.com');
        window.location = 'contactus.html';
    </script>
<?php
}
?>
Quote:
And this is the Email I receive:
From: Seb
E-mail: szpadlolaizer@gmail.com
Postal Code:
Telephone:
Service: General Cleaning
Frequency:
Message: hi
As you can see I am missing values for Postal Code, Telephone and Frequency.
To make it easier, this is form on the website:
HTML Code:
<h3>Contact Form</h3>
                                            <form action="contact.php" method="post" enctype="multipart/form-data" id="ContactForm">
                                            	<div>
                                                	<label>

                                                    	Enter your name<br />
                                                       <input class="imInput imInput_1" type="text" name="cf_name" id="Itm_8_00_3" onkeypress="return imKeyFilter(0,event);" />
</label>
                                                    <label>
               	                    Enter your e-mail<br />
                                                        <input type="text" name="cf_email" value="" />
                                                    </label>
                                                    <label>

               	                    Enter your postal code<br />
                                                        <input type="text" name="cf_message" value="" />
                                                    </label>
                                                    Enter your telephone number<br />
                                                    <input type="text" name="cf_message" value="" />
                                                    </label>
                                                    Service Type<br />

	<select class="imInput imInput_1" name="cf_service" id="Itm_8_00_5">
		<option selected="selected">-</option>
		<option>General Cleaning </option>
		<option>Commercial Cleaning</option>
		<option>Move in/out Cleaning</option>
	</select>
    Cleaning Frequency:<br />

	<select class="imInput imInput_1" name="cf_message" id="Itm_8_00_6">
		<option selected="selected">-</option>
		<option>Daily</option>
		<option>Weekly</option>
		<option>Bi-weekly</option>
		<option>Monthly</option>

		<option>One-time</option>
	</select>
</label>
<br />
                                                    Enter your message<br />
                                                    <textarea cols="10" rows="3" name="cf_message"></textarea>
                                                </div>
                                                <div class="container">

                                                    <a href="#" class="right" onclick="document.getElementById('ContactForm').submit()">Send</a>
                                                   	<a href="info@cleaningcrazy.com" class="right" onclick="document.getElementById('ContactForm').reset()">Clear</a>
                                                    <p/> 
                                                </div>
                                            </form>
chartkor is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 02-04-2012, 06:47 PM
  #4
Pegasus
Mama Hen
 
Pegasus's Avatar
 
Join Date: Nov 2001
Location: 35º South of Santa Claus
Posts: 25,491
iTrader: (0)
Pegasus is a splendid one to beholdPegasus is a splendid one to beholdPegasus is a splendid one to beholdPegasus is a splendid one to beholdPegasus is a splendid one to beholdPegasus is a splendid one to beholdPegasus is a splendid one to behold
I'm not an expert on it, but you have in your HTML, name="cf_message" several times, most notably in the three areas that aren't showing up. Shouldn't it be changed to "cf_postalcode", etc.?
Pegasus is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 02-05-2012, 01:43 AM
  #5
chartkor
Novice (Level 1)
 
Join Date: Jan 2012
Posts: 5
iTrader: (0)
chartkor is an unknown quantity at this point
Wierdly it was all good, I guess it must have been some sort of a lag on my website. All cf parameters were correct all the time. Now it works for good 6 hours I think and I haven't touched anything.
Anyhow, thank you for your help gentlemen.
chartkor is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Old 02-05-2012, 02:39 AM
  #6
Reiss
Super Guru
 
Join Date: Oct 2006
Location: London. UK
Posts: 577
iTrader: (0)
Reiss will become famous soon enough
As Pegasus noted, each input field needs to have a unique name.
Reiss is offline   Add to del.icio.us Add to del.icio.us    Can you digg it?Can you digg it? Reply With Quote
Reply
KEEP TABS
SPONSORS
 
Boxedart

 
 


 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
  
 
 
 



 
  POSTING RULES
 
 
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Thread Tools
Display Modes

Forum Jump

 

All times are GMT -5. The time now is 08:15 PM.

   

Mascot team created by Drawshop.com | Web Hosting

Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

Server Monitoring by ENIACmonitor 0.01
HTMLforums.com © Big Resources, Inc. Web Design by BoxedArt.com
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.