I have a website with HTML form where after pressing "Sumbit" I need that information to be passed to Docusign as well as Zapier. I've done it with having two buttons but trying to figure out a way to do it with one button using JavaScript.
Ideally when Submit button is pressed I need data to be passed to Zapier without opening Zapier success page and just redirect to Docusign page passing there all info from my web form. How can I achieve it with Javascript?
Here is my html code with two buttons:
<form class="item" id="form" action="https://demo.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=*********" method="POST">
<div class="box">
<div class="form-group">
<label>What product are you applying for?</label>
<input type="text" class="form-control" name="product" value="EFTPOS">
</div>
<div class="title-form">
<h5>Business Details:</h5>
</div>
<div class="form-group">
<label>Merchant Trading Name:</label>
<input type="text" class="form-control" name="merchantName">
</div>
<div class="text-center">
<button class="btn btn-success btn-lg" type="submit" formaction="https://demo.docusign.net/Member/PowerFormSigning/*******" name="button" onclick="$('form').attr('target', '_blank')">Submit</button>
<button class="btn btn-success btn-lg" type="submit" formaction="https://hooks.zapier.com/hooks/catch/*****/*****/" onclick="$('form').attr('target', '_blank')">BUTTON 2</button>
</div>
</div>
</form>
I've tried suggested code from another post similar to mine but it's not working: When I try this code below it's just not doing anything at all:
$(function () {
var dataString = $(this).serialize();
$('#form').on('submit', function () {
$.ajax({
type: 'POST',
url: "https://demo.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=963864ea-9fde-4243-bcd1-380c5747876a&env=demo&acct=38dc928a-8528-4368-ba2b-d9d980c9a213&v=2",
crossDomain: true,
data: dataString,
success: function (responseData, textStatus, jqXHR) {
var value = responseData.someKey;
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
}).then(function () {
$.ajax({
type: 'POST',
url: "https://hooks.zapier.com/hooks/catch/14888944/33njn26/silent/",
crossDomain: true,
data: dataString,
success: function (responseData, textStatus, jqXHR) {
var value = responseData.someKey;
},
error: function (responseData, textStatus, errorThrown) {
alert('POST failed.');
}
})
})
return false
})
})
When I try this code below it posts the data to Zapier (first link) but doesn't post it to the Docusign:
$(function () {
$('form').submit(function () {
var data = $(this).serialize();
$.post("https://hooks.zapier.com/hooks/catch/14888944/33njn26/silent/", data, function () {});
$.post("https://demo.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=963864ea-9fde-4243-bcd1-380c5747876a&env=demo&acct=38dc928a-8528-4368-ba2b-d9d980c9a213&v=2", data, function () {});
return false;
});
});
and it gives me this error:
"index.html:1 Access to XMLHttpRequest at 'https://demo.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=963864ea-9fde-4243-bcd1-380c5747876a&env=demo&acct=38dc928a-8528-4368-ba2b-d9d980c9a213&v=2' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
jquery.min.js:4
POST https://demo.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=963864ea-9fde-4243-bcd1-380c5747876a&env=demo&acct=38dc928a-8528-4368-ba2b-d9d980c9a213&v=2 net::ERR_FAILED 307 (Temporary Redirect)"
Docusign link was working in a separate html button but not working when doing this code above