Question

I have two forms in wordpress contact us page. One form use simple mail() and the other uses mail() with attachment. I have to process these forms in a single page. I'm using inner.php (wordpress) to process forms. I can process multiple forms from different pages, but I'm unable to process forms from the same page. How can I do this. Any help will be appreciated. Thanks in advance...

Was it helpful?

Solution

I know that the way most people treat multiple forms on one page is to have each form post to another PHP file where the form is validated, its information is entered into a database or an email is sent off. So you usually have something like this:

<form name="contactform" method="post" action="sendmail.php">
blah blah blah
</form>

<form name="mailinglist" method="post" action="join.php">
blah blah blah
</form>

That work great, but why would you create all those extra files when you can just have the form post to the same file and create multiple functions to process your multiple forms. The solution is very simple and super efficient. First, lets create some forms.

<form name="mailinglist" method="post">
<input type="text" name="email" />
<input type="submit" name="mailing-submit" value="Join Our Mailing List" />
</form>

<form name="contactus" method="post">
<input type="text" name="email" />
<input type="text" name="subjet" />
<textarea name="message"></textarea>
<input type="submit" name="contact-submit" value="Send Email" />
</form>

Now lets put some PHP code before the tag to have different processes for each form.

<?php 
if (!empty($_POST['mailing-submit'])) {
   //do something here;
}

if (!empty($_POST['contact-submit'])) {
   //do something here;
}
?>

Now all you need to do is create your processes within those two “if” statements and each form will be dealt with accordingly when it it filled and submitted.

This will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top