[英]Submit form after an javascript function is completed [PHP]
Merry Christmas everyone. 大家圣诞快乐。 I'm building a small landing page and i have a form in it.
我正在构建一个小的目标网页,并且其中有一个表单。 I have monetized this form with CPA offers, what i would like to happen is to get the user input AFTER the content locking widget has closed.
我已经使用CPA产品通过此表格获利,我希望发生的是在内容锁定小部件关闭后获取用户输入。 I tried many ways but im having errors, and the form submits itself once you click the button and the user doesn't haves to complete the offers.
我尝试了很多方法,但是我遇到了错误,单击按钮后表单便会自动提交,而用户不必完成报价。 The javascript function i have to call is
call_locker();
我必须调用的javascript函数是
call_locker();
How can i submit my form after the call_locker();
我该如何在
call_locker();
之后提交表格call_locker();
function is completed? 功能完成了吗?
<html>
<head>
<meta charset="UTF-8">
<title>Complete a survey to become part of our team.</title>
<!-- Start of content locker code -->
<noscript><meta http-equiv="refresh" content="0;url=https://www.appcaptcha.com/contentlockers/noscript.php" /></noscript>
<script type="text/javascript">var ogblock=true;</script>
<script type="text/javascript" src="https://www.appcaptcha.com/contentlockers/load.php?id=76db12dda6691911c8a119fe7043facd"></script>
<script type="text/javascript">if(ogblock) window.location.href = "https://www.appcaptcha.com/contentlockers/adblock.php";</script>
<!-- End of content locker code -->
</head>
<body>
<?php
$userErr ="";
$emailErr ="";
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if (strpos($url, 'error=user-empty') !== false) {
$userErr ="Please enter your username!";
}
if (strpos($url, 'error=email-empty') !== false) {
$emailErr ="Please enter your email!";
echo $emailErr;
}
if (strpos($url, 'error=email-incorrect') !== false) {
$emailErr ="Please enter a valid email!";
echo $emailErr;
}
if (strpos($url, 'error=succes') !== false) {
$entry = 'You have entered succesfully!';
}
?>
<h1> Please enter the following info: </h1>
<form method="post" action="enter.php">
Username: <input type="text" name="username" placeholder="Username" /> <br>
<span class="error"><?php echo $userErr ?></span><br>
E-mail: <input type="text" name="email" placeholder="E-mail" /><br>
<span class="error"><?php echo $emailErr ?></span><br>
Social Media: <input type="text" name="smedia" placeholder="Enter your Facebook, twitter, Skype, profile URL" /> (Optional)<br>
<input type="submit" value="Enter" />
<?php echo $entry ?>
</form>
</body>
</html>
<?php
include 'connect-mysql.php';
$username = $_POST['username'];
$email = $_POST['email'];
$smedia = $_POST['smedia'];
if(empty($username)) {
header("Location: index.php?error=user-empty");
exit();
}
if(empty($email)) {
header("Location: index.php?error=email-empty");
exit();
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: index.php?error=email-incorrect");
exit();
}
else {
$sql = "INSERT INTO user (username, email, socialmedia) VALUES ('$username', '$email', '$smedia')";
$result = mysqli_query($dbcon, $sql);
header("Location: index.php?error=succes");
};
?>
Set id attribute as "myForm" for your form and use the following at the end of your javascript function. 将表单的id属性设置为“ myForm”,并在javascript函数末尾使用以下内容。
document.getElementById("myForm").submit();
EDIT: And call the function with the button click instead of using submit button. 编辑:并单击按钮而不是使用提交按钮来调用该函数。
You need to prevent the submit button from submitting the form, hence use: "event.preventDefault();" 您需要阻止“提交”按钮提交表单,因此请使用:“ event.preventDefault();” or "return false;"
或“返回假”; event.preventDefault() vs. return false
event.preventDefault()与返回false
Then at the end of your scripts you can submit the form by using: document.getElementsByTagname("form")[0].submit(); 然后,可以在脚本末尾使用以下方式提交表单:document.getElementsByTagname(“ form”)[0] .submit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.