PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 17th, 2012, 02:09 AM
raybrown raybrown is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 raybrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 5 sec
Reputation Power: 0
Contact Form

Hi there,
I am building a website at the moment using Dreamweaver and need to do a form on the contact page. Can anyone help me produce a working form with Php code and a thankyou for contacting us page ?? The form fields are Name:, Email:, Tel:, Message: and the Submit button.
Any help would be greatly appreciated, as I am pulling out the hair I have left grrrrrrrrr!!

This post has been edited by Rayb: Today, 01:08 AM

Reply With Quote
  #2  
Old July 17th, 2012, 01:30 PM
tomVance tomVance is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 tomVance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 33 sec
Reputation Power: 0
With out knowing exactly what you want the PHP to do here is a basic example:

Code:

<form action="url to the php script .php" method = "POST" >

<label for="name">Name:</label><input type="text" name="name" />

<label for="email">Email:</label><input type="email" name="email" />

<label for="tel">Telephone:</label><input type="text" name="tel" />

<label for="message">Message:</label><textarea name="message"></textarea>


</form>


And here is the php:

PHP Code:
<?php

$name 
mysql_real_escape_string($_POST['name']);
$emailmysql_real_escape_string($_POST['email']);
$telmysql_real_escape_string($_POST['tel']);
$messagemysql_real_escape_string($_POST['message']);

// do what you wish with the values.

?>



This is a very basic example but hopefully this gives you an idea of what to do.

Reply With Quote
  #3  
Old July 17th, 2012, 02:42 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Dev Shed God 30th Plane (19500 - 19999 posts)
 
Join Date: Jul 2004
Location: USA
Posts: 19,834 Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 48th Grade (Above 100000 Reputation Level) 
Time spent in forums: 6 Months 1 Day 21 h 3 m 17 sec
Reputation Power: 4192
Welcome to DevShed Forums, raybrown.

"A little knowledge is a dangerous thing." You will probably want to do some error checking in the PHP code as well.

@tomVance The "for" attribute of <label> elements should reference the ID of a form field. Your form fields lack IDs.
__________________
Spreading knowledge, one newbie at a time. I'm available for hire at Dynamic Site Solutions.

Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

Remember people spend most of their time on other people's sites (so don't violate web design conventions).

Reply With Quote
  #4  
Old July 17th, 2012, 02:56 PM
tomVance tomVance is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 7 tomVance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 33 sec
Reputation Power: 0
Quote:
Originally Posted by Kravvitz
Welcome to DevShed Forums, raybrown.

"A little knowledge is a dangerous thing." You will probably want to do some error checking in the PHP code as well.

@tomVance The "for" attribute of <label> elements should reference the ID of a form field. Your form fields lack IDs.


Kravviz is right the labels need to relates to the ID attribute for the input elements i missed them out, sorry.

Reply With Quote
  #5  
Old July 18th, 2012, 08:38 AM
raybrown raybrown is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 raybrown User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 37 m 5 sec
Reputation Power: 0
Contact form

Thanks TomVance

I want the PHP to send the contents from the input fields in the form and display a thankyou message to say we will be in contact soon, see my coding below, hope you can help or make it simple for me :-)

Code:

<form name="contactform" method="post" action="send_form_email.php">
<table width="450px" align="center">
 <tr>
   <td valign="top">
      <label for="first_name">First Name *</label>
        </td>
        
          <td valign="top">
    <input  type="text" name="first_name" maxlength="50" size="30">
      </td>
       </tr>
       
<tr>
  <td valign="top">
     <label for="last_name">Last Name *</label>
       </td>  
       <td valign="top">
          <input  type="text" name="last_name" maxlength="50" size="30"> 
           </td>
            </tr>
            
<tr>
  <td valign="top">
     <label for="email">Email Address *</label>
       </td>
         <td valign="top">  
          <input  type="text" name="email" maxlength="80" size="30"> 
           </td>
            </tr>
            
<tr> 
 <td valign="top">
    <label for="telephone">Telephone Number</label> 
     </td>
     
<td valign="top">
   <input  type="text" name="telephone" maxlength="30" size="30">  
   </td>
    </tr>
    
<tr>
  <td valign="top">
     <label for="comments">Comments *</label> 
      </td>
      
      <td valign="top">
         <textarea  name="comments" maxlength="1000" cols="25" rows="6">
         </textarea>
           </td>
            </tr>
            
             <tr>  <td colspan="2" style="text-align:center">   
             <input type="submit" value="Submit">
               </td> 
               </tr>
               
                </table> </form>


And here is the php:

PHP Code:
<?php
 
if(isset($_POST['email'])) {
$email_to "";
$email_subject "Your email subject line";
function 
died($error) {
// 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['first_name']) ||
!isset(
$_POST['last_name']) ||
!isset(
$_POST['email']) ||
!isset(
$_POST['telephone']) ||
!isset(
$_POST['comments']))
{     
died('We are sorry, but there appears to be a problem with the form you submitted.'); } 
$first_name $_POST['first_name'];
 
// required 
$last_name $_POST['last_name'];
 
// required    
 
$email_from $_POST['email'];
 
// required
$telephone $_POST['telephone'];
 
// not required
$comments $_POST['comments'];
// 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 .= 'The Email Address you entered does not appear to be valid.<br />';} 
$string_exp "/^[A-Za-z .'-]+$/";
if(!
preg_match($string_exp,$first_name)) {     $error_message .= 'The First Name you entered does not appear to be valid.<br />';}
if(!
preg_match($string_exp,$last_name)) {     $error_message .= 'The Last Name you entered does not appear to be valid.<br />';}
if(
strlen($comments) < 2) {     $error_message .= 'The Comments you entered do not appear to be valid.<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 .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";     $email_message .= "Comments: ".clean_string($comments)."\n"; }
  
?>

Reply With Quote
  #6  
Old July 20th, 2012, 03:52 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,805 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 17 h 43 m 13 sec
Reputation Power: 6112
Given that the OP contains an edit message from another forum, I'm sure nobody is surprised that he's been cross-posting to at least 2 other forums.

This thread is a spam magnet, so I'm closing it.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Contact Form

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap