The following is my HTML:
Set action
attribute of your form
tag to the URL of the page to send the data to.
I have the form and it POSTs to login.php but I want the button Make a new account post the same data to register.php.
Is that possible?
In HTML5 it is, using the formaction attribute on the submit button.
But browser support is probably not so good yet. Could be resolved using a Polyfil that attaches click handlers to such buttons automatically and changes the action
attribute of the form dynamically, though.
Try the following:
In HTML add an onclick event handler for Make a new account
button:
<form class="form-horizontal" method="post" id="myform">
<div class="control-group">
<label class="control-label" for="inputEmail">Email</label>
<div class="controls">
<input type="text" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<input type="password" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox"> Remember me
</label>
<button type="submit" class="btn btn-success">Sign in</button>
<button class="btn btn-primary" onclick="javascript:register()"> Make a new account </button>
</div>
</div>
</form>
In JavaScript:
function register() {
this.action = 'register.php';
return true;
}
If this does not work, you may try:
function register() {
var frm = document.getElementById("myform");
frm.action = 'register.php';
return true;
}
One or both of the above mentioned solution should work for you. Prefer the first approach as it is cleaner.
Please take this as a starting point not a copy-paste solution and follow the best practices for development.
<form class="form-horizontal" method="post" action="register.php">