Skip to main content
smartCode
Known Participant
May 24, 2013
Answered

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

  • May 24, 2013
  • 2 replies
  • 5236 views

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.

This topic has been closed for replies.
Correct answer bregent

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.


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.

2 replies

smartCode
smartCodeAuthor
Known Participant
May 28, 2013

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.

Participating Frequently
May 28, 2013

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?

smartCode
smartCodeAuthor
Known Participant
May 30, 2013

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

}

?>

Participating Frequently
May 24, 2013

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.