Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem with two form actions in form tag

Member
 
Join Date: May 2008
Posts: 118
#1: Oct 19 '09
Hi,



I am getting the problem with form tag. i,e in in form action i am placing the some autoresponder page like

<form name="form1" method="post" action="http://www.autoresponder.com">
When i submit this form it goes to the page http://www.autoresponder.com .Along with this i want to run some extra functionality(mail sending) after the form submission .like
<?
//test mail
mail($to,$subject,$message)
?>

How can i run both the mail functionality and form action at the same time of form submission. Anybody please help me how i approch.



Thanks
Sravani

ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,440
#2: Oct 19 '09

re: Problem with two form actions in form tag


Php is executed line by line on the server side, and you can use conditional statements to manage the execution flow.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if($_POST){
  3. mail(.....)
  4. }
  5. ?> 
  6.  
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,761
#3: Oct 19 '09

re: Problem with two form actions in form tag


Quote:

Originally Posted by swethak View Post

How can i run both the mail functionality and form action at the same time of form submission. Anybody please help me how i approch.

PHP is executed server-side, the form action is performed client-side.
Once your client is able to submit the form, your PHP code has long since finished executing.

If you want to execute some code when the user submits the form, you need to either do that on the page that the form is submitted to, or do it client-side before the form is submitted.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 919
#4: Oct 19 '09

re: Problem with two form actions in form tag


I suspect that you will need to look at AJAX to submit data without sending it in traditional html. That way when a user clicks submit it can run a script in the background and then submit the page. The challenging part will be having two information/warning boxes.

I personally think that Atli's solution of having it all on one page is much easier. Using a simple include() the main part of the form processor can include the mail part from a separate file.
Reply