Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Re: Submiting a webform via the submit button of a webpage.

Explorer ,
May 24, 2013 May 24, 2013

Copy link to clipboard

Copied

Hi Folks,

I need some help on the contact page of my website, so that users can fill-out a form with their names, email addresses, and type a brief message

in the message box, and submit the form via the submit button.

Any suggestions with the full javascript code or php to submit the page.

Please help.

Thanks.

TOPICS
Server side applications

Views

4.7K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 21, 2013 Jun 21, 2013

Your form contains php code and is on an .hmtl page. Unless you have specifically modified your server, pages with php need to have a .php extension. Change http://www.simpsys.co.uk/customer_services.html to http://www.simpsys.co.uk/customer_services.php and see if that works any better.

Votes

Translate
LEGEND ,
May 24, 2013 May 24, 2013

Copy link to clipboard

Copied

Start by checking with your host to see if they provide a formail script - many do. If they don't, a search on the web for 'php formmail script' should give you some ideas.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

Hi bregent,

Thanks for your reply, yes my host provides a formail script - but that seems not to be the problem, I think the problem is with the 'php script' itself, I need to insert a php or javascript that handles 'formmail', inside the html file, I dont have any yet, but I have created the html file with all the correct coding inside it, all I need now is the php script. Can you help.

Thanks.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 28, 2013 May 28, 2013

Copy link to clipboard

Copied

Sorry, I don't understand what you are saying. What problem is with the 'php script itself'.  Have you tried implementing the hosts solution? Are you getting an error message? What are the symptoms? Who is the host and have you read their instructions for implementing their php formmail script?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

Hi,

Thanks for your reply, in regards to the 'formmail script' you asked earlier, few days ago, no they dont, apologies for that, I have just found out they don't.  The issue is that when I click on the submit button, the form does not submit at all, and there is no error message or anything.

I now have the 'formmail script' you suggested earlier, please have a look below to see and advise me, If I need to correct any areas that needs changing, before I test it to see if it works.

Thanks for your help.

This is the script - php

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

<?php

if(isset($_POST['email'])) {

   

   

    $email_to = "";

    $email_subject = "";

   

   

    function died($error) {

        error code

        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";

   

   

// create email headers

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers); 

?>

<!--  -->

Thank you for contacting us. We will be in touch with you very soon.

<?php

}

?>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 30, 2013 May 30, 2013

Copy link to clipboard

Copied

Good, now please post the code from the page where the form is located.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 04, 2013 Jun 04, 2013

Copy link to clipboard

Copied

Hi Bregent,

I received your reply thanks.

This is the code you requested for, please see below, the code inserted inside the HTML FORM.  I have also posted a copy of the page, to show you how it looks in a live web browser, you will notice that some lines of code is popping out beyond the Logo at the top of the page, I dont know why this is showing, this is a seperate issue anyway.

Thanks for your help.

The code and the html form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="http://www.simpsys.co.uk"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simpsys/contact_page</title>
<link href="styles/simpsys_cs5.css" rel="stylesheet" type="text/css" />
</head>

<body>
<center>
<?php
if(isset($_POST['email'])) {
    
    $email_to = "info@www.simpsys.co.uk";
    $email_subject = "Web Design";
    
    
    function died($error) {
        // your 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";
    
    
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 
?>

<!-- <form name="contactform" method="post" action="send_form_email.php" enctype="application/x-www-form-urlencoded" id="contactform">
     
      <p> </p>
     
      <p>Your first name: *     
     
         <label for="firstname"></label>
     
          <input type="text" name="firstname" id="firstname" maxlength"40" size="30" tabindex="1" />
         
      </p>
      
      <p>Your last name: *
         
          <label for="lastname"></label>
         
          <input type="text" name="latname" id="lastname" maxlength="40" size="31" tabindex="2" />
    
      </p>
   
      <p>Your eamil: *
     
        <label for="email"></label>
     
        <input type="text" name="email" id="email" maxlength="40" size="35" tabindex="3" />
     
      </p>
     
      <p>Telephone:
     
        <label for="telephone"></label>
     
        <input name="telephone" type="text" maxlength="40" size="37" tabindex="4" />
       
      </p>
     
      <p>Your message:</p>
     
      <p>
     
        <label for="message"></label>
       
        <textarea name="message" id="message" cols="47" rows="10" tabindex="5"></textarea>
       
      </p>
     
      <p>
     
    <input type="submit" name="submit" id="submit" value="Submit">
     
      </p>
  
      <h1>Thanks.</h1>

   </form> -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
}
?>

</center>

<div id="container">
  <div id="banner"><img src="Images/Simpsys-Logo-2.jpg" width="260" height="100" /></div>
  <div id="top_bar"><a href="index.html">Home</a> | <a href="about_us.html">About Us</a> | <a href="contact_us.html">Contact Us</a> | <a href="customer_services.html">Customer Services</a> | Mobile 07951 643023</div>
<div id="centre_column">
    <p>Please fill the webform below with the required information we need to tell us your enquiry, or the service you require, and we will  get back to you within five working days.</p>
    <p> </p>
   <form name="contactform" method="post" action="send_form_email.php" enctype="application/x-www-form-urlencoded" id="contactform">
     
      <p> </p>
     
      <p>Your first name: *     
     
         <label for="firstname"></label>
     
          <input type="text" name="firstname" id="firstname" maxlength"40" size="30" tabindex="1" />
         
      </p>
      
      <p>Your last name: *
         
          <label for="lastname"></label>
         
          <input type="text" name="latname" id="lastname" maxlength="40" size="31" tabindex="2" />
    
      </p>
   
      <p>Your eamil: *
     
        <label for="email"></label>
     
        <input type="text" name="email" id="email" maxlength="40" size="35" tabindex="3" />
     
      </p>
     
      <p>Telephone:
     
        <label for="telephone"></label>
     
        <input name="telephone" type="text" maxlength="40" size="37" tabindex="4" />
       
      </p>
     
      <p>Your message:</p>
     
      <p>
     
        <label for="message"></label>
       
        <textarea name="message" id="message" cols="47" rows="10" tabindex="5"></textarea>
       
      </p>
     
      <p>
     
    <input type="submit" name="submit" id="submit" value="Submit">
     
      </p>
  
      <h1>Thanks.</h1>

   </form>

See a 'COPY' of the page - how it looks in a live web browser.

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"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> Thank you for contacting us. We will be in touch with you very soon.
Home | About Us | Contact Us | Customer Services | Mobile 07951 643023

Please fill the webform below with the required information we need to tell us your enquiry, or the service you require, and we will get back to you within five working days.

Your first name: *

Your last name: *

Your eamil: *

Telephone:

Thanks.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 04, 2013 Jun 04, 2013

Copy link to clipboard

Copied

That page is a complete mess   You've got duplicated form code that is commented out - remove that to make the code easier to read. Next, none of your form fields on your form match the names you are using in the script. They must match EXACTLY. Start by fixing those problems and see if it works.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

Hi Bregent,

I have fixed the problems you mentioned earlier, the duplicated form code has now been removed to make it easier to read, but the whole form is not there anymore when I click the design view of dreamweaver, it disappears completely.  Next, the form fields in the form now match the names in the script exactly, I have run a test to see if it works and it works, but with errors on the page when the form sends.  'Error 404'.  Code is showing at the top of the form, and the page "Thank you for contacting us we will be in touch with you soon" does not display after the form has been submitted.  These are what I discovered.

Regards

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 07, 2013 Jun 07, 2013

Copy link to clipboard

Copied

Please copy and paste the entire code from the page.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2013 Jun 11, 2013

Copy link to clipboard

Copied

Hi Bregent,

Please see below the entire code from the page.

This is the page with the CODE! showing at the top - Thanks for your help.

Please fill the webform below with the required information we need to tell us your enquiry, or the service you require, and we will get back to you within five working days.


"; echo $error."

"; echo "Please go back and fix these errors.

"; 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.
'; } $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.
'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.
'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.
'; } if(strlen($error_message) >

Your first name: *

Your last name: *

Your email: *

Telephone:

Your message:

Thanks.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 11, 2013 Jun 11, 2013

Copy link to clipboard

Copied

Your code did not come through correctly. Please switch to the advanced editor and paste your code into your post using the double chevron icon on the toolbar, and selecting Syntax Highlighting > Plain.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2013 Jun 11, 2013

Copy link to clipboard

Copied

Hi, now using the advanced editor.

The page with the CODE! - Hope this comes through correctly.

Please fill the webform below with the required information we need to tell us your enquiry, or the service you require, and we will get back to you within five working days.

"; echo $error."

"; echo "Please go back and fix these errors.

"; 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.

'; } $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.

'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.

'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.

'; } if(strlen($error_message) >  

Your first name: *

Your last name: *

Your email: *

Telephone:

Your message:

Thanks.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 12, 2013 Jun 12, 2013

Copy link to clipboard

Copied

That code you posted is not valid. Does that match exactly what's in your page? Is that the complete code from the page?

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 13, 2013 Jun 13, 2013

Copy link to clipboard

Copied

Hi Bregent,

What I posted is the complete contact page of the website, after testing it, with the instructions you gave me earlier, to remove the duplicate form code, and to match the form fields "names" exactly.  The complete code from the html page, with the php "form mail script" embedded in it, is what you have already with you, the only difference is that I have removed the duplicate form.

I thought this might help, to let you know that when I hit the submit button, It sends, while sending, an "Error 404" message flashes for a few seconds, and that's all it says, nothing else.  What I noticed is that, the code showing at the top of the contact page, is part of the php code embedded in the html.  Appreciate your help.

This is a link to the site. http://www.simpsys.co.uk

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 21, 2013 Jun 21, 2013

Copy link to clipboard

Copied

Hi Bregent, please let me know when you have a solution or any suggestion to the problem whether now or in the future, I have clicked on the 'helpful link' for you to get your points, I really appreciate your help.

Thanx a lot.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2013 Jun 21, 2013

Copy link to clipboard

Copied

LATEST

Your form contains php code and is on an .hmtl page. Unless you have specifically modified your server, pages with php need to have a .php extension. Change http://www.simpsys.co.uk/customer_services.html to http://www.simpsys.co.uk/customer_services.php and see if that works any better.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines