Jump to content

Automatically Submitting a Form WITH Submit Button


Recommended Posts

You have multiple forms on the page. You should only have 1 form, which contains everything that you want to submit when you submit the form. Your submit button is inside its own form, when you submit that it's not going to submit all of the other fields because those other fields aren't in the same form as the submit button.Other than that, will you have this on a server that has PHP available, or any other server-side language that you can use to send the email?

Link to comment
Share on other sites

Yes, your code has all sorts of problems. You have divs all over the place. All divs should be inside the body. You also have multiple style blocks when only one is necessary, and you broke the form into multiple forms. Your code should always have the general form of...

<!DOCTYPE html><html><head><meta charset="utf-8"><title>title</title><style></style></head><body></body></html>
Link to comment
Share on other sites



I have the following Form on my page = image 1


I am struggling to get the 'submit' button to automatically submit to an e-mail address, and then display a "Your message has been submitted' message.

Can someone please help me with this?


My code is attached.


Thank you!


Thought I'd tell you how you would be able to do it.


Basically, what you need is to use PHP to send the mail to your email address, using the variables inputted into the form.


http://www.w3schools.com/php/php_mail.asp is a useful URL for you to see what you need to do, but I'll explain it below.


Basically, this page says this code;

<?php// display form if user has not clicked submitif (!isset($_POST["submit"])) {  ?>  <form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">  From: <input type="text" name="from"><br>  Subject: <input type="text" name="subject"><br>  Message: <textarea rows="10" cols="40" name="message"></textarea><br>  <input type="submit" name="submit" value="Submit Feedback">  </form>  <?php } else {    // the user has submitted the form  // Check if the "from" input field is filled out  if (isset($_POST["from"])) {    $from = $_POST["from"]; // sender    $subject = $_POST["subject"];    $message = $_POST["message"];    // message lines should not exceed 70 characters (PHP rule), so wrap it    $message = wordwrap($message, 70);    // send mail    mail("webmaster@example.com",$subject,$message,"From: $fromn");    echo "Thank you for sending us feedback";  }}?>

In essence, this code uses the following step-flow;

  1. Checks if the form has already been submitted
  2. Checks that the user has filled in the 'from' field
  3. Defines the variables, and calls them
  4. Then you would need to edit the message, to something similar to; $message = "Variable 1: {$variable1}, Variable 2: {$variable2} etc."
  5. Then your email address would replace "webmaster@example.com", telling the server where to send the email with the variables to.
  6. Then it echos a response and informs the user that the submission was successful

I hope this helps you.


Please like it if it's what you're looking for.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...