tags:

views:

68

answers:

5

I would like to create an HTML form with one field for user name, a second under it for password, and then below that a row containing two buttons, one to login and another to register.

I want the 'Log In' button to submit the form. I don't want the register button to submit the form, but rather take the user to a different page. How can I get the two buttons to appear in row with each other and have the behavior that I described?

A: 

use those in one row inside <span></span> those in different rows inside <div></div>

You can checkout <table> as well, but it's not the trend nowadays ;)

a little code to get you started:

<form>
 <div>name: <input></input></div>
 <div>password: <input></input></div>
 <div><span><button>Login</button></span> <span><button>Register</button></span></div>
</form>

Be aware, that this code is just an illustration for the basic layouting, not a working code. Submitting from a form, and the used elements can vary depending on your exact requirements.

Balint Pato
A: 

you can do this with some PHP:

The HTML file:

<form  method="post" action= "action.php">

Name : <input type="text" name="name"/><br /><br />

<input type="submit" value="b1" name="action" />

<input type="submit" value="b2" name="action" /><br /><br />

</form>

The PHP action file:

<?php

    echo "<h1> Hello $name </h1>";

    if ($action == "b1")
    echo "you just clicked button 1";
    if ($action == "b2")
    echo "you just clicked button 2";

    ?>
The Worst Shady
I suggest using <br> tags is not really neat: http://webdesign.about.com/b/2008/11/08/dont-use-br-for-layout.htm
Balint Pato
+2  A: 
<input type="button"    value=" Log in "    onclick="document.form.action='http://example.com/loginPage.php';        document.form.submit();">
<input type="button"    value=" Register "  onclick="document.form.action='http://example.com/registrationPage.php'; document.form.submit();">
Babiker
Thanks! It took me a second to realize that I needed to change 'form' to be the name of my form though.
samoz
A: 

With ONLY plain HTML i don't think you can submit and redirect to two separate pages. Either use a server side language to find out which button was clicked and login/redirect accordingly.

Or use a submit button and text with a anchor tag for the registration link.

Ranhiru Cooray
+1  A: 

To me, it's important to at least try to use just plain old HTML, no JS or PHP or any kind of script:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html><head>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >
  <title>Pure HTML submit and link buttons</title>
</head><body>

<div>
  <form action="http://www.mysite.com/login.html" method="post">
    <p><input type="submit" value = "Log In">
      <a href ="http://www.mysite.com/register.html"&gt;&lt;span&gt;
        <input type="button" value = "Register"></span></a></p>
  </form>

<a href=""http://validator.w3.org/#validate_by_input"&gt;html valid?</a>

</body></html>
Pete Wilson
Isn't the onclick action JavaScript though?
samoz
Thanks! Yes, it sure is, but it was only for the "html valid?" button, not the "Log In" and "Register" buttons. I made it a link so as to remove any confusion.
Pete Wilson