Adding a button to form - html

<form class="user" method="POST" action="{{ url('login') }}?next={{next_url}}">
{{ csrf_token()|raw }}
<div class="form-group">
<input type="email" name="email" required="required" id="email" aria-describedby="emailHelp" placeholder="{{ _('Enter Email Address...') }}">
</div>
<div class="form-group">
<input type="password" name="password" required="required" autocomplete="false" id="password" placeholder="{{ _('Password') }}">
</div>
<button type="submit">
{{_("Login")}}
</button>
</form>
I need to add a button for register (example.com/register) below the login button. But when I add that when the user clicks on the Register button, It says that Email and password fields are required. How to resolve this issue?
Register button code: <button href="{{ url('register') }}">{{_("Create an Account!")}}</button>

The HTML button tag can be of 3 types: submit, reset and button. If you do not specify the type it will default to submit. If the button then happens to be inside a form, it will try to submit it, hence the error you are getting.
There are a couple options you have here:
Specify the type of the button:
<button type="button" href="{{url('register')}}">{{_("Create an Account!")}}</button>
Put the button outside the form:
<form>
</form>
<button ....>
Use e.preventDefault() in javascript if you have an onclick method for the button:
function buttonClick(e) {
e.preventDefault(); // this will prevent the default behavior of a submit
// button which is to submit a form
// ...
}

Set type to button instead of submit (default value).
<button type="button">Register</button>

Just do a seperate Form
<form action="{{ url('register') }}"
<button type="submit">Create an Account!</button>
</form>

Another Solution if you are using MVC.
You can create the button in your Function register (Controller) then just call it to form
Controller: <div class=\"col-lg-5 col-xs-5\"> <button type='button' class='btn btn-success btn-block' id='register' > Create Account </button> </div>
$data['btn']=$btn;
View:
<form>
<?=#$btn ?>
</form>
Or just do other form
<form>
<button type='button' class='btn btn-success btn-block' id='register'> Create Account</button>
</form>

Related

Form doesn't work when submit button is in the modal window

I have HTML form with submit button inside. Inside the form there are piece of HTML code which popups in modal window when filling up the form. Inside this modal are one more input and submit button. And it does not work, the form doesn't send to email. But when I move entire button HTML code right before </form> then submit button works. Here is a code:
<form name="autoForm" id="contact-form" class="row" method="post" action="php/send.php">
<div class="form-group col-md-6">
<label id="address-label" for="place">* Markė | modelis | metai | TA | miestas</label>
<input id="form_place" type="text" name="place" class="form-control" data-error="Laukas privalomas" >
<div class="help-block with-errors"></div>
</div>
<div class="form-group col-md-12">
<label for="message">Automobilio būklė</label>
<textarea id="form_message" name="message" class="form-control h-auto" rows="4" data-error="Prašau, parašykite daugiau apie NT"
placeholder="Čia galite parašyti daugiau informacijos apie automobilio būklę"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="submit-container col mt-5">
<a class="btn btn-primary" id="to-modal-form"><font size="4">Sužinoti kainą</font></a>
</div>
<div id="modal-background" class="modal-background container-hidden">
<div id="modal-form" class="modal-form">
<a id="modal-close"><i class="icon-close" data-v-27b8b94e=""></i></a>
<div class="form-header">
<h2>Gaukite kainos pasiūlymus tiesiai į savo telefoną.</h2>
<p>Įveskite telefono numerį ir gaukite pasiūlymo nuorodą <b>SMS</b></p>
</div>
<div class="form-body">
<div class="form-group col-md-6">
<label class="phone" for="phone">* Jūsų telefono numeris</label>
<input id="form_phone" type="phone" name="phone" class="form-control" required="required" data-error="Laukas privalomas">
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="code" value="" id="code" />
<button class="btn btn-primary" type="submit" id="form_submit"><font size="4">Tęsti</font></button>
<span class="privacy">Sutinku su privatumo politika</span>
</div>
</div>
</form>
Filling up first inputs there are first button <a class="btn btn-primary" id="to-modal-form"><font size="4">Sužinoti kainą</font></a> which is opening the modal windows. Inside after filling up additional input I press <button class="btn btn-primary" type="submit" id="form_submit"><font size="4">Tęsti</font></button> which doesn't work.
But form work when button is moved before </form>. Form sends all values - inside and out of modal window.
Can't get what is wrong.
If you have button outside </form> it would not work the solution is using form="" parameter to the button it basically tell this button belong to this specific form element
<button class="btn btn-primary" form="contact-form" type="submit" id="form_submit"><font size="4">Tęsti</font></button>
Your submit button will confused which form that it should submitted if you place it outside the form tag.
You could use javascript to submit the form.
https://www.javascript-coder.com/javascript-form/javascript-form-submit/
Put a button inside your modal with onclick="submitForm('contact-form');", then add below js code
function submitForm(id) {
document.getElementById(id).submit();
}
Solved this by adding submit button before with attribute hidden:
<form>
<!-- the form content -->
<button class="btn btn-primary" type="submit" id="form_submit" hidden></button>
</form>
And that button inside of modal window made as trigger with attribute onclick="submitForm();" like this:
<button class="btn btn-primary" onclick="submitForm();"><font size="4">Tęsti</font></button>
In JS it triggers submit button using .click() method:
const submitBtn = document.getElementById('form_submit');
function submitForm() {
submitBtn.click();
}

Angular/ HTML: After click or press Enter call a function

I have a input field and after clicking a button I'm calling a function and get back the right things.
Now I also want that the function is calling after pressing enter.
At the moment my code looks like this:
<div class="input-group mb-3">
<input (keyup)="searchUser($event)" stype="text" class="form-control" placeholder="Suche nach Nachnamen ..."
aria-label="Recipient's username" aria-describedby="button-addon2">
<div class="input-group-append">
<button (click)="searchForUser()" class="btn btn-outline-secondary" type="submit"
id="button-addon2">Suche</button>
</div>
</div>
I already tried to put my div in a <form></form>. Then the whole page is reloading.
Wrap the input and the button in a form tag, and rather than using a click handler on the button, make it a submit handler on the form element.
<form (submit)="searchForUser()">
Alternatively, you can remove the type="submit" completely.
This is working for me:
<form #p="ngForm" (ngSubmit)="searchForUser(u)">
<div class="input-group mb-3">
<input (keyup)="searchUser($event)" stype="text" class="form-control"
placeholder="Suche nach Nachnamen ..." aria-label="Recipient's username" aria-describedby="button-addon2">
<div class="input-group-append">
<button class="btn btn-outline-secondary" type="submit" id="button-addon2">Suche</button>
</div>
</div>
</form>
Explanation: https://angular.io/api/forms/NgForm

All buttons in <form> are posting

I have a form with multiple textboxes and buttons. I want to use some of the buttons to clear the textbox. But when I click on the button Clear text the form gets posted.
Does someone know how I can fix this?
Here is my HTML:
<form name="reaction" method="post" action="./send.php">
<input type="text" name="firstname">
<button class="btn btn-default" onclick="ClearText1();">Clear text</button><br />
<input type="text" name="lastname">
<button class="btn btn-default" onclick="ClearText2();">Clear text</button><br />
<button class="btn btn-block btn-success">Send</button>
</form>
use <button type="submit" for submit button and <button type="button" for other button.You can read More about button here.
From MDN
The type attribute of the button. Possible values are:
submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
reset: The button resets all the controls to their initial values.
button: The button has no default behavior. It can have client-side scripts associated with the element's events, which are triggered when the events occur.
menu: The button opens a popup menu defined via its designated element.
<form name="reaction" method="post" action="./send.php">
<input type="text" name="firstname">
<button type="button" class="btn btn-default" onclick="ClearText1();">Clear text</button><br />
<input type="text" name="lastname">
<button type="button" class="btn btn-default" onclick="ClearText2();">Clear text</button><br />
<button type="submit" class="btn btn-block btn-success">Send</button>
</form>
Use event.preventDefault(); to prevent default submit behavior for this button.
<script>
function ClearText2(event){
// your code....
event.preventDefault();
}
</script>

HTML multiple form post

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();
}

Submitting/detecting a submit a form by clicking on a CSS button

I am experiencing a issue detecting if the submit button was clicked. I was give the following form by a CSS designer:
<form action="" method="post">
<div class="form-group">
<label>Username</label>
<input name="username" type="text" class="form-control span12">
</div>
<div class="form-group">
<label>Password</label>
<input name="password" type="password" class="form-controlspan12 form-control">
</div>
Sign In
<div class="clearfix"></div>
</form>
I would like submit the captured information by clicking on the Sign In CSS button. I am used to the usual:
<input type="Submit" value="Sign-In>
button, but not this is different, I am stuck. Any assistance will be appreciated.
try to change
Sign In
with
<button type="submit" class="btn btn-primary pull-right">Sign In</button>
Furthermore you need to set an action attribute on your form element
Give your form and ID = "myform" And try below:
Sign In