HTML, making a button submit data to another url? - html

The following is my HTML:
<form class="form-horizontal" method="post">
<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"> Make a new account </button>
</div>
</div>
</form>
Note: Just in case someone is wondering, it is utilizing the bootstrap
library.
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? If so, how?

Set action attribute of your form tag to the URL of the page to send the data to.

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.

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.

<form class="form-horizontal" method="post" action="register.php">

Related

Cannot read property 'form' of undefined angular 5

I have the following html form in angular
<form (ngSubmit)="signin()" #signinform="ngForm">
<div class="form-group row">
<label for="signinemail" class="col-sm-2 col-form-label">Email:</label>
<div class="col-sm-10">
<input type="email"
class="form-control"
id="signinemail"
name="signinemail"
ngModel
placeholder="Email">
</div>
</div>
<div class="form-group row">
<label for="signinpassword" class="col-sm-2 col-form-label">Password:</label>
<div class="col-sm-10">
<input type="password"
class="form-control"
id="signinpassword"
name="signinpassword"
ngModel
placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="form-check">
<input class="form-check-input ml-0"
type="checkbox"
id="gridCheck"
name="remembercheckbox"
ngModel>
<label class="form-check-label" for="gridCheck">
Remember Me
</label>
</div>
<small class="form-text text-muted">Forget Password?</small>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary">Sign In</button>
<button type="button" class="btn btn-outline-dark" (click)="c('Close click')">Close</button>
</div>
</form>
and the following typescript for the form:
import {NgForm} from "#angular/forms";
#ViewChild('signinform') signinform: NgForm;
signin() {
let payload = {
email: this.signinform.form.value.signinemail,
password: this.signinform.form.value.signinpassword,
localstorage: this.signinform.form.value.remembercheckbox
};
this.userservice.gettoken(payload);
this.signedin = true;
}
I have compared this to other forms I have built and yet there is no difference. What could be causing this?
the form element is on the dom when I call. The submit button is within the form. The #ViewChild element syntax is correct and properly imported. I truly don't understand and I am ready to punch a baby.
The code looks fine...You could just try not using view child, and instead do:
<form (ngSubmit)="signin(signinform)" #signinform="ngForm">
signin(form: NgForm) {
console.log(form);
}
I'd definitely try that console though, to make sure the form is being submitted properly.

Form not submitting values inside <div>

I am working with Laravel 5.4 Framework and I get this issue when the form does not submit anything except the csrf_token().
If I put an input outside of those <div> it will work and submit it, otherwise the browser (Chrome) will only submit the token, as if everything inside the <div> is not part of the form.
How can I submit all the data while using Bootstrap's form-group divs? The layout is not the problem as it does not work even when removing it.
#extends('layouts.master')
#section('content')
<div class="container" style="margin-top: 1%">
<p>Welcome, {{$user->name}}, here you can submit a new company for our database.</p>
<form name="suggestCompanyForm" method="post">
{{csrf_field()}}
<div class="form-group">
<label for="companyName">Company Name</label>
<input type="text" class="form-control" id="companyName" aria-describedby="companyNameHelp" placeholder="Enter company name">
<small id="companyNameHelp" class="form-text text-muted">Enter the company's name you would like to suggest</small>
</div>
<div class="form-group">
<label for="companyEmail">Email address</label>
<input type="email" class="form-control" id="companyEmail" aria-describedby="emailHelp" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">Enter the company contact email.</small>
</div>
<div class="form-group">
<label for="selectCategory">Select main category</label>
<select class="form-control" id="selectCategory">
<option>Food&Drink</option>
<option>Cosmetics</option>
<option>Electronics</option>
<option>Consumer Goods</option>
<option>Services</option>
</select>
</div>
<div class="form-group">
<label for="description">Company description.</label>
<textarea class="form-control" id="description" rows="5"></textarea>
</div>
<div class="form-group">
<label for="logo">File input</label>
<input type="file" class="form-control-file" id="logo" aria-describedby="logoHelp">
<small id="fileHelp" class="form-text text-muted">Add company logo.</small>
</div>
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" id="check" class="form-check-input">
I agree that my submission follows the website rules.
</label>
</div>
<button id="submitCompany" type="submit" class="btn btn-primary" >Submit</button>
</form>
</div>
#endsection
your form inputs are not being submitted because you didn't give them names ...
Try
<textarea class="form-control" name="description" id="description" rows="5"></textarea>
You have to add the action attribute to the form tag.
Edit this line
<form name="suggestCompanyForm" method="post">
to
<form name="suggestCompanyForm" action = "<url-for-the-submission>" method="post">
.You will also need to add this
name="name_of_input_to_submit"
to each input not only the textarea and you are also uploading a file you have to add this to the form tag too.
enctype="multipart/form-data"

HTML Form Post handling

I have a form as detailed below. It uses a post method to send data to getUsername.php. This file echoes some JSON results from mysql db.
Am wondering how do I grab this data? When I hit submit it navigates to the file and displays the JSON. I want to grab the JSON and stay on the same page or move to a different one!
I have kept the php file simple because the data is also used for returning data to my android app.
<div class="well bs-component">
<form id ='formLogin' action="http://localhost/getUsername.php" method="post" class="form-horizontal">
<fieldset>
<legend>Sign In</legend>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input name='email' type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword" class="col-lg-2 control-label">Password</label>
<div class="col-lg-10">
<input name='password' type="password" class="form-control" id="inputPassword" placeholder="Password">
<div class="checkbox">
<label>
<input type="checkbox"> Checkbox
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="reset" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
I believe this cannot be done from a form. I instead used jquery post function to return data

How to connect pre-build HTML Form to a database using Ruby?

I know that with ruby you can use the scaffolding command, and it'll make the html form for you. But i already create the HTML Form manually, and i don't know how to connect your existing HTML Form to a database using Ruby. I create the HTML around Bootstrap framework, and place the form within a Modal.
Here is a snippet of my HTML Form:
<div class="modal fade" id="signModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h6 class="modal-title2">Sign Up Form</h6>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="InputEmail">Email</label>
<input type="email" class="form-control form-control-inline" id="InputEmail" placeholder="Email">
</div>
<div class="form-group">
<label for="InputFirst">First Name</label>
<input type="text" class="form-control form-control-inline" id="InputFirst" placeholder="First Name">
</div>
<div class="form-group">
<label for="InputLast">Last Name</label>
<input type="text" class="form-control form-control-inline" id="InputLast" placeholder="Last Name">
</div>
</form>
<label for="mobilePhone">Mobile Phone</label>
<form class="form-inline">
<div class="form-group">
<input type="tel" class="form-control" id="mobilePhone" placeholder="Mobile Phone">
</div>
<div class="form-group">
<select class="form-control">
<option>Android</option>
<option>iOS</option>
</select>
</div>
</form>
<div class="formButton">
<button type="submit" class="btn btn-primary" data-dismiss="modal">Submit</button>
</div>
</div>
</div>
</div>
</div> <!-- End Modal -->
I'm still new to Ruby. Hope i explained my question well. Thanks a bunch! :D
You have to use rails form or simple form gem to convert your form. Please check rails guide or simple form documentation for details.

Rails and Bootstrap 3: How to get first and last name on same line?

I have been unable to get First and Last name fields on the same line, and at half the width of the other lines - email, password, etc.
I have tried various changes to including the addition of "form-horizonal", col-xs-6, but didn't solve it.
I would like to make the well look like this (currently the are all the same sized, stacked on top of each other):
Excerpt of index.html.erb:
<form class="form-signin col-sm-4 well" role="form">
<h2 class="form-signin-heading">Sign Up</h2><hr>
<form class="form-inline" role="form">
<form class="form-horizontal">
<div class="form-group col-xs-6">
<label class="sr-only" for="#">First name</label>
<input type="text" class="form-control" id="#" placeholder="First name">
</div>
</form>
<form class="form-horizontal">
<div class="form-group col-xs-6">
<label class="sr-only" for="#">Last name</label>
<input type="text" class="form-control" id="#" placeholder="Last name">
</div>
</form>
<div class="form-group">
<input type="email" class="form-control" placeholder="Email address">
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Type email again">
</div>
<div class="form-group">
<input type="password" class="form-control" placeholder="Password">
</div>
<div class="form-group">
<div class="">
<div class="checkbox">
<label>
<input type="checkbox"> Remember me
</label>
</div>
</div>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign Up</button>
</form>
</form>
All help greatly appreciated.
Full index.html.erb -
https://gist.github.com/attatae/11022245
Bootstrap 3 Grid Overview (yes, I looked too):
http://getbootstrap.com/css/#grid
Another related question that I looked at, but didn't solve:
Bootstrap 3: How to get two form inputs on one line and other inputs on individual lines?
Here is what I came up with
I hasten to add that the solution may be different because of the fact that it's bootstrap. My solution doesnt take that into consideration at all, because I'm not familiar with it. It may be as easy as changing some of the classes. Good luck to you...