Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

php - One form, One submission button, but TWO actions

I have a form that collects client's info and then it

  • saves them in the database
  • sends out few emails
  • sends the info to SalesForce (SF) department

Now, the first 2 two task was easy, but the third one is giving me trouble. For SF i don't have do anything special, just have to add their url and they will pull out all the necessary info they need from the form. To me it seems like in order to do these i need the form have 2 actions associated with one submit button (can't have 2 forms or 2 buttons).

So in my raf.php file I have this form, and after submission i have to redirect them to raf-submitted.php page that displays the success/error message and other necessary info.

The form (got the idea from here)

 <form id="referralForm" name="referralForm" autocomplete="off" enctype="multipart/form-data" method="POST">

 <input id="saveForm" name="saveForm" class="field-submit" type="button" value="Submit" style="padding-left:20px" width="100" tabindex="23" onclick="FormSubmission(); SalesForceSubmission();" />

 </form>

The JavaScript:

 $(document).ready(function()
 { 
    function SalesForceSubmission()
    {
       document.referralForm.action = "https://someAddress.salesforce.com/";
       document.referralForm.submit();          
       return true;
    }

    function FormSubmission()
    {
       document.referralForm.action = "raf-submitted.php";
       document.referralForm.submit();          
       return true;
    }
  });

The raf-submitted.php file take cares of the form validation, database insertion and email issues.

It's not working. I also tried these with no luck:

Can someone please help me? Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Once a form is submitted, you are no longer on that page. You've navigated away.

The other way you can do this is submit the first action via AJAX, then submit the form naturally to the second destination. I would suggest using jQuery to make your AJAX calls since most of the AJAX code is already there for you to use.

Another option is to have raf-submitted.php perform a POST from your server to the salesforce server once it receives the form data. See: Post to another page within a PHP script


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...