I have two forms in my page.
<form name="form1" action="" method="POST" autocomplete="off">
<h3><span>Number : </span>
<span class="min-width"><select class="form-control" id="num" maxlength="255" name="num_selector" onchange="this.form.submit();" autofocus>
<option value="0001" selected="selected">0001</option>
</select></span>
</h3>
</form>
<form action="/enter" method="POST" name="form2">
<input class="btn btn-default btn-orange has-spinner" type="submit" value="enter" name="enter">
</form>
When i click the enter button on the form2, it end up posting to the same URL(which is what defined in form1). form1 is getting posted instead form2.
You can submit them using the java-script separatly.
document.getElementById("myForm").submit();
<input type="button" name ="enter" value="enter" OnClick="postData('FORMID')" />
function postData(formId){
document.getElementById(formId).submit();
}
Related
I have this HTML code:
<form class="w3-center w3-padding-16" method="get" action="" >
<input type="search" name="q" placeholder="Buscar en {{categoria}}" autofocus required>
<input type="submit">
</form>
My goal is to send the input text to URL. For example if I write "admin" on the textbox the page redirects to "https://example.com/admin"
Add onsubmit to the form, and a JS script. Like this:
function redirect(){
window.location.href="http://www.example.com/" + document.getElementById("urlInput").value;
}
<form id="my-form" onsubmit="redirect(); return false" class="w3-center w3-padding-16" method="get" action="" >
<input id="urlInput" type="search" name="q" placeholder="Buscar en {{categoria}}" autofocus required>
<input type="submit">
</form>
Here is the form I created:
<div align="center">
<form id="example_form" action="/">
<fieldset>
<legend></legend><input id="date" type="date" value="today" />
<input class="formbutton" type="submit" value="submit" /></fieldset>
</form>
<form action="#" method="post"></form>
</div>
Try following: This is very basic code where form action will be URL of the page.
<form action="/action_page.php" method="get" target="_blank">
Date: <input type="date" type="date" value="today"><br>
<input type="submit" value="Submit" class="formbutton">
</form>
How do I send the contents of the form with out sending the contents of my other form on the same page? For example
<form class="form" method="get" action="page.php">
<input type="text" value="hi" name="forminput1">
<input type="submit" value="send">
</form>
<form class="form" method="get" action="page.php">
<input type="text" value="byebye" name="forminput2">
<input type="submit" value="send">
</form>
page.php:
if (isset($_GET['forminput1'])) {
//some code
}
if (isset($_GET['forminput2'])) {
//some code
}
Whenever I submit form #2, I end up submitting form #1.
You have not given any of your inputs a name attribute. Without a name="somename" attribute the browser will not pass anything back on the GET or POST.
If you add a name attribute like this
<form class="form" action="page.php">
<input type="text" value="hi" name="data">
<input type="submit" value="send" name="send">
</form>
<form class="form" action="page.php">
<input type="text" value="byebye" name="data">
<input type="submit" value="send" name="send">
</form>
It will suddenly start to work as you expect.
If you want to make both forms unique you can add a different name to the submit buttons.
<form class="form" action="page.php">
<input type="text" value="hi" name="data">
<input type="submit" value="send" name="send_form1">
</form>
<form class="form" action="page.php">
<input type="text" value="byebye" name="data">
<input type="submit" value="send" name="send_form2">
</form>
and then in your PHP, you will be able to differentiate between which form (button) is being submitted like this
<?php
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['send_form1'])) {
// User sent form1
}
if ( $_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['send_form2'])) {
// User sent form2
}
I think you are using the same action....Forms are independent
As we have number of input fields and there are some fields as required example:
<input placeholder="Role" type="text" required/>
<span ng-show="Role" class="text-danger">Role is required.</span>
<input placeholder="Title" type="text" required/>
etc..
<button type="button" ngclick="Savereferences()">Save</button>
Now i want to validate this fields on click of Save button in angular js, Can any one help me out how to do this.
<input placeholder="Role" ng-model="Role" type="text" required/>
<span ng-show="RoleMsg" class="text-danger">Role is required.</span>
<input placeholder="Title" ng-model="Title" type="text" required/>
etc..
<button type="button" ngclick="Savereferences()">Save</button>
JS Code for validating Role
$scope.Savereferences=function(){
if($scope.Role){
$scope.RoleMsg=true;
}
}
You can do like this...using ng-required and form
<form role="form" id="form" name="form" class="form-horizontal">
<input placeholder="Role" id="role" name="role" type="text" ng-required="true"/>
<span ng-show="form.role.$error.required">Role is required.</span>
//Same as other field
<button type="button" ng-disabled="!form.$valid" ngclick="Savereferences()">Save</button>
</form>
Hey Everyone: I'm working on a simple login system and wanted to keep my styled buttons inline with each other in the form but assign different actions to them. Is this possible? Obviously the following code won't work as written. I want the login button to link to my login.php script and my sign-up button to link to the signup.html page.
<form action="login.php" method="post">
Username:
<input name="username" type="text" class="clear" size="20">
<br><p></p>
Password:
<input name="password" type="password" class="clear" size="20"><br><p></p>
<input name="login" type="submit" id="login" value="Log In">
<input name="signup" type="button" id="signup" value="Sign Up">
</form>
As always thanks so much!
You can use javascript for doing this
HTML
<form action="login.php" method="post">
Username:
<input name="username" type="text" class="clear" size="20">
<br><p></p>
Password:
<input name="password" type="password" class="clear" size="20"><br><p></p>
<input name="login" type="submit" id="login" value="Log In">
<input name="signup" type="button" id="signup" onclick="loadsign();" value="Sign Up">
</form>
you can use this JAVASCRIPT
<script type="text/javascript">
function loadsign(){
window.location.assign( provide path of html file );
}
</script>
Hope this could help you !
I have changed code a bit hope it could deliver.