2015-06-27 142 views
0

我正在做一個下拉菜單項登錄,但我不知道如何驗證表單輸入。我有一個頁面,註冊時會被重定向到一個PHP文件與下面的代碼:如何使用PHP驗證HTML文件中的表單輸入?

<?PHP 
require_once("./include/membersite_config.php"); 

if(isset($_POST['submitted'])) 
{ 
    if($fgmembersite->RegisterUser()) 
    { 
     $fgmembersite->RedirectToURL("thank-you.html"); 
    } 
} 

?> 

此代碼,然後重定向到另一個HTML文件。最終,你重定向到與下面的代碼的login.php文件:

<?PHP 
require_once("./include/membersite_config.php"); 

if(isset($_POST['submitted'])) 
{ 
    if($fgmembersite->Login()) 
    { 
     $fgmembersite->RedirectToURL("../index.html"); 
    } 
} 

?> 

這一切工作正常,但我與它的問題是,它現在只能通過單獨的頁面登錄。我希望能夠通過下拉菜單進行登錄,但我無法使用與上述相同的PHP代碼,因爲下拉列表位於HTML文件內。如何:

  • 使用PHP驗證表單輸入
  • 將用戶重定向到他們時,他們點擊下拉菜單項進行訪問該頁面

編輯:這是我在使用形式我login.php文件:

<form id='login' action='<?php echo $fgmembersite->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'> 
<fieldset > 
<h2 class="titel2">Log in</h2> 

<input type='hidden' name='submitted' id='submitted' value='1'/> 


<div><span class='error'><?php echo $fgmembersite->GetErrorMessage(); ?></span></div> 

    <input class="veld" placeholder="Gebruikersnaam" type='text' name='username' id='username' value='<?php echo $fgmembersite->SafeDisplay('username') ?>' maxlength="50" /><br/> 
    <span id='login_username_errorloc' class='error'></span> 

    <input class="veld" placeholder="Wachtwoord" type='password' name='password' id='password' maxlength="50" /><br/> 
    <span id='login_password_errorloc' class='error centreren'></span> 

    <div class="centreren"></div><a class="anormaal" href='reset-pwd-req.php'>Wachtwoord vergeten?</a></div> 

    <input class="knop2" type='submit' name='Submit' value='Log in' /> 

</div> 
</fieldset> 
</form> 

回答

0

你需要更具體的驗證,這裏是例子,你可以幫助。

if(empty($_POST['something']) === TRUE) 
{ 
    $error[]= 'Your field is empty'; 
} 

使用此重定向:

header('Location: 'yourphpscript.php'); 
exit;