2

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. 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();

How can i submit my form after the call_locker(); function is completed?

index.php

<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>

enter.php

<?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");


    };
?>
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123

2 Answers2

0

Set id attribute as "myForm" for your form and use the following at the end of your javascript function.

document.getElementById("myForm").submit();

EDIT: And call the function with the button click instead of using submit button.

smozgur
  • 1,772
  • 1
  • 15
  • 23
  • And what about the PHP form handling ? When i call the function on button click, the PHP form handling doesnt works and the user can input any kind of information. – Sviatoslav Volkov Dec 25 '16 at 12:52
  • submit button vs form.submit() action, they both do the same thing from PHP perspective. Meaning, form should be posted to PHP same way. You just execute your javascript before form submit as difference what you need. – smozgur Dec 25 '16 at 12:56
0

You need to prevent the submit button from submitting the form, hence use: "event.preventDefault();" or "return false;" event.preventDefault() vs. return false

Then at the end of your scripts you can submit the form by using: document.getElementsByTagname("form")[0].submit();

Community
  • 1
  • 1
vicgoyso
  • 636
  • 1
  • 14
  • 35