0

I have a form that has 2 buttons on it. 1 will send a email using a .php script,and another will submit the form to a .php database. Both of these work great by themselves, but I would like to combine them into 1 button. here is a example of my code:

<FORM name="drop_list" action="<?php echo $editFormAction; ?>"" method="POST" >
    <input name="emailForm" type="button" id="emailForm" onClick="sendFormEmail()" value="Email">
    <input name="add_patient" type="submit" id="add_patient" onclick=document.drop_list.action='<?php echo $editFormAction; ?>' value="Add Patient">

Here is the java script that is run for the email button:

function sendFormEmail() //email form
    {
        document.drop_list.action = "html_form_send.php";
        document.drop_list.target = "_blank";
        document.drop_list.submit();             // Submit the page
        return true;
    }

I am still very new to php script and javascript, so any help is appreciated.

Gregg
  • 1
  • 1
  • 1
  • Combine the 2 PHP scripts that handle the form and send the email. – Mark Parnell May 21 '13 at 23:03
  • Yes, you want a single php file that does both, and use that as the form action. If that's not an option, you could do it all using javascript. Send the email via ajax, then submit the form in the callback. – Tap May 21 '13 at 23:11
  • I think what OP is trying to do is dynamically send an email as opposed to reloading the page and then sending the email? – James May 22 '13 at 00:26

1 Answers1

0

Just use mail(to,subject,message,headers,parameters) in the send email function. The function arguments have to be the strings where you store the text of the form fields, so you can fill the mail() function with the email and other data inserted in the user interface.

check this to get to know how to actually call a function declared in the same file Calling a particular PHP function on form submit

Community
  • 1
  • 1