2015-05-28 29 views
1

我正在創建登錄功能,但我還需要一個註冊按鈕。此註冊按鈕必須與登錄功能的形式相同,因爲我需要以塊形式顯示它們。HTML - 表單中的按鈕打開鏈接

我有這個

<form class="login" onsubmit="return validate();" method="get" action="php/home.php"> 
    <input class="login-panel credentials" id="username" placeholder="Username" name="username"/> 
    <input class="login-panel login-button" id="submit" value="Login" type="submit"/> 
</form> 

用於登錄,但我也需要一個註冊按鈕,用戶到另一個頁面重定向。但是由於表單已經有了一個動作,我該如何添加這個按鈕:

<input class="login-panel login-button" type="submit" value="Register"/> 

到表單並仍然能夠將用戶重定向到另一個頁面?

+0

你可以給它一個'onclick = myFunction()'javascript並使用它來重定向到你的註冊頁面。只需使用'type =「按鈕''而不是'type =」submit「' – Jared

回答

-3

您應該創建一個按鈕:

<input type="button" onclick="location.href='php/register.php'" value="Register" /> 
+0

按鈕元素等同於OP發佈中的輸入元素。這並沒有解決這個問題。 – Sablefoste

+0

對不起,編輯了我的答案。 – prigero

0

我會用一個動作的形式,然後在目標頁面的邏輯。例如,對於PHP:

<?php 

if(isset($_POST['submit']) && $_POST['submit']=='Login'){ 
    include("/yourloginscript.php"); 
} else { 
    include("/yourregistrationscript.php"); 
} 

?> 
0

,我可以從你的行動領域用PHP看,所以你可以是這樣的:

1.增加一個name屬性的提交按鈕:

<input name='login' class="login-panel login-button" id="submit" value="Login" type="submit" /> 
<input name='register' class="login-panel login-button" type="submit" value="Register" /> 

然後調整你的PHP文件,因此用戶重定向如果$ _ POST [ '註冊']被派往:

//First use filter_input to clean your post 
    $post_array = filter_input_array(INPUT_POST); 
    //then check the kind of action your user wants to do 
    if(isset($post_array['register'])){ 
     //will trigger if the register submit button was used 
     //So you can redirect the user using header like so: 
     header("location:https://yoursite.com/register.php"); 
    }elseif(isset($post_array['login'])){ 
     //will trigger if the login submit button was used 
    } 

通過經驗,如果在單個表單上使用多個提交按鈕,則只有單擊的提交按鈕將在POST中發送。因此,您可以有多個提交按鈕併爲其中的每一個觸發不同的操作。

相關問題