admin管理员组文章数量:1122846
i need the user to send 2 forms with one button-click, so i'm basically trying to merge two buttons into a third one, in order to pass data along, but don't know what i'm doing wrong here.
i've been trying to get this solution to work, but i get console-error
"uncaught typeerror: cannot read property 'submit' of null at SubmitForms"
one of the forms is generated with ninjaforms, the other one by another plugin... i'm not sure if i can address/call the ninjaform id or its name in the right way. where is any of the two to be found? i tried many different variations, all with the same result.
so, my (third) button is hooked in like this:
...
function button() {
echo '<input type="button" name=button class=button value="click me" onclick="submitForms()" />';
}
and this is what the js looks like (in header):
<script>
submitForms = function(){
document.getElementById("ninja_form_id_2").submit();
document.getElementById("id_form_2").submit();
}
</script>
i never used javascript before, so i'm not sure if i implemented it like i should. thanks for help!
i need the user to send 2 forms with one button-click, so i'm basically trying to merge two buttons into a third one, in order to pass data along, but don't know what i'm doing wrong here.
i've been trying to get this solution to work, but i get console-error
"uncaught typeerror: cannot read property 'submit' of null at SubmitForms"
one of the forms is generated with ninjaforms, the other one by another plugin... i'm not sure if i can address/call the ninjaform id or its name in the right way. where is any of the two to be found? i tried many different variations, all with the same result.
so, my (third) button is hooked in like this:
...
function button() {
echo '<input type="button" name=button class=button value="click me" onclick="submitForms()" />';
}
and this is what the js looks like (in header):
<script>
submitForms = function(){
document.getElementById("ninja_form_id_2").submit();
document.getElementById("id_form_2").submit();
}
</script>
i never used javascript before, so i'm not sure if i implemented it like i should. thanks for help!
Share Improve this question edited Dec 18, 2017 at 13:49 user133428 asked Dec 18, 2017 at 13:38 user133428user133428 14 bronze badges 2- first java != javascript. next you should use ajax for this or combine the 2 forms. – Thomas Commented Dec 18, 2017 at 13:45
- that's the problem, i can't access the plugin-generated form in order to just change it. if so i would not try to find a workaround. so how would it work with ajax? i'm no dev... – user133428 Commented Dec 18, 2017 at 13:53
1 Answer
Reset to default 0I partially stole this answer from SO
$("#idForm").submit(function(e) {
var url = "path/to/your/script.php"; // the script where you handle the form input.
$.ajax({
type: "POST",
url: url,
data: {
form1: $("#idForm").serialize(),
form2: $("#idForm2").serialize()
},
// serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
e.preventDefault(); // avoid to execute the actual submit of the form.
});
So basically you prevent the normal submit of your forms, serialize it's content to json and send that in an ajax call to the server.
本文标签: pluginshow to send two forms with one click (script ninjaforms id)
版权声明:本文标题:plugins - how to send two forms with one click (script ninjaforms id) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736289662a1928352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论