Laravel 4 auto inserting </form> - forms

I updated Laravel 4.1 recently and an exiting modal window form is not working correctly. I have figured out that for some reason after the Laravel 4.1 update, Laravel is auto inserting an tag into my modal body. (I have the Form::close() in the footer. I was just curious if anyone else has seen this or can offer an explanation of why this is happening and how to prevent it. I am good about searching through my issues, but this one is not yielding me any results.
Note that if I move my submit button into the modal-body div, then submit works as expected and updates goes through the normal process.. but for some reason with this particular modal, having the submit button in the footer puts the submit button outside of the form as the form close is auto inserted before the end of the modal-body div. Also strangely enough I have this working on another page, and everything works as expected.
Here is the relevant code:
<div class="modal-body">
<?php
$access = Session::get('user_access');
$userid = Session::get('user_id');
?>
{{ Form::open(array('method'=>'POST','route' => 'users.store', 'style' => 'display:inline')) }}
#foreach($user as $userinfo)
<!-- Set hidden form element with userid embedded -->
<input type="hidden" name='id' id='id' value={{ $userid }}>
<!-- Display the username and profile Picture -->
<h2><center>{{ $userinfo->username }}</center></h2>
<br><br>
<!-- 2 Column Form to change user information and display current status -->
<div class ='container col-md-offset-1'>
<div class='row col-md-3'>
<div>
{{ Form::label('givenname', 'First Name:') }} <br>
<input type="text" name='givenname' id='givenname' value={{ $userinfo->givenname }}>
</div><br />
<div>
{{ Form::label('surname', 'Last Name:') }} <br>
<input type="text" name='surname' id='surname' value={{ $userinfo->surname }}>
</div><br />
<div>
{{ Form::label('email', 'Email Address:') }} <br>
<input type="text" name='email' id='email' value={{ $userinfo->email }}>
</div><br />
</div>
<div class='row col-md-3'>
<div>
{{ Form::label('password', 'New Password:') }} <br>
<input type="password" name='password' id='password' value={{ $userinfo->password }}>
</div><br />
<div>
{{ Form::label('password_confirmation', 'Confirm New Password:') }} <br>
<input type="password" name='password_confirmation' id='password_confirmation' value={{ $userinfo->password }}>
</div><br />
<div>
{{ Form::label('useraccess', 'Current Subscription Status:') }} <br>
{{ $access }}
</div><br />
</div>
</div>
#endforeach
</div> <!-- End Modal Body -->
<div class="modal-footer">
{{ Form::submit('Save', array('class' => ' btn btn-warning')) }}
<!-- Close the form -->
{{ Form::close() }}
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
When I run the developer tools in the browser, I can see the auto insert
<form method="POST" action="http://dev.app.myapp.com/users" accept-charset="UTF-8"><input name="_token" type="hidden" value="<TOKEN">
<!-- Set hidden form element with userid embedded -->
<input type="hidden" name="id" id="id" value="6">
<!-- Display the username and profile Picture -->
<h2><center>johndoe123</center></h2>
<br><br>
<!-- 2 Column Form to change user information and display current status -->
<div class="container col-md-offset-1">
<div class="row col-md-3">
<div>
<label for="givenname">First Name:</label> <br>
<input type="text" name="givenname" id="givenname" value="John">
</div><br>
<div>
<label for="surname">Last Name:</label> <br>
<input type="text" name="surname" id="surname" value="Doe">
</div><br>
<div>
<label for="email">Email Address:</label> <br>
<input type="text" name="email" id="email" value="johndoe#notarealemail.com">
</div><br>
</div>
<div class="row col-md-3">
<div>
<label for="password">New Password:</label> <br>
<input type="password" name="password" id="password" value="Encrypted Password String">
</div><br>
<div>
<label for="password_confirmation">Confirm New Password:</label> <br>
<input type="password" name="password_confirmation" id="password_confirmation" value="Encrypted Password String">
</div><br>
<div>
<label for="useraccess">Current Subscription Status:</label> <br>
User </div><br>
</div>
</div>
</form>
<div class="modal-footer">
<input class=" btn btn-success" type="submit" value="Save">
<!-- Close the form -->
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

The reason is that your mark-up is lacking proper structure. You begin the <form> in some element, then close it inside another element.
Check out the page source (ALT+CMD+U on Mac). You will notice </form> exactly where you originally put Form::close() (inside <div class="modal-footer">).
That position, however, is invalid mark-up, as I mentioned before. The browser doesn't know exactly what you want, but it will try to come to a conclusion, so it correctly moves </form> down one level.
What you are seeing in developer tools is not what was printed out by Laravel, but actually how the browser interpreted your invalid mark-up.
A solution for this specific case: move Form::close() after <div class="modal-footer">.

Related

using the form template in bootstrap for styling only

can I use only the layout of the form in bootstrap and have the input option frozen and the submit buttons behave like plain html button which redirects somewhere?
Why I want this?
So in the homepage I have resources which can be deleted pressing the delete button against them. On clicking the delete button the resource data is displayed like the layout of a form, of course I want typing inputs to be disabled, and a warning message on top, and YES and RESET option at the bottom. Since the form has a specific action assigned via GET method it will invariably perform that action irrespective of the choice selected. So if RESET is also selected the resource still gets deleted.
One option is to have the buttons as individual links with specific redirection properties but then I need to handcode the entire styling of the form.
Below is the code
#elseif($layout=='delete')
<div class="container-fluid mt-4">
<div class="row">
<section class="col md-7">
<div class="card mb-3">
<img src="https://cdn.pixabay.com/photo/2014/05/05/19/53/keyboard-338502_1280.jpg" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title">Are you sure you want to delete</h5>
<form action="{{url('/destroy/'.$student->id)}}" method="get">
#csrf
<div class="form-group">
<label>CNE</label>
<input value="{{ $student->cne }}" type="text" class="form-control" name="cne" placeholder="Enter CNE">
</div>
<div class="form-group">
<label>FirstName</label>
<input value="{{ $student->firstName }}" type="text" class="form-control" name="firstName" placeholder="Enter the first Name">
</div>
<div class="form-group">
<label>Last Name</label>
<input value="{{ $student->LastName }}" type="text" class="form-control" name="LastName" placeholder="Enter the Last Name">
</div>
<div class="form-group">
<label>Age</label>
<input value="{{ $student->age }}" type="text" class="form-control" name="age" placeholder="Enter Age">
</div>
<div class="form-group">
<label>Speciality</label>
<input value="{{ $student->Speciality }}" type="text" class="form-control" name="Speciality" placeholder="Enter the speciality">
</div>
<input type="submit" class="btn btn-info" value="yes">
<input type="submit" class="btn btn-warning" value="reset">
</form>
</div>
</div>
</section>
Firstly, if you want disable input, add readonly to your inputs :
<input value="{{ $student->cne }}" type="text" class="form-control" name="cne" placeholder="Enter CNE" readonly>
Second, now the type of your reset button = submit so when you click it, your form is submitted. Change your code :
<input type="reset" class="btn btn-warning" value="reset">

How to access to RESTController through a controller?

I am using Spring.
The method in my RESTController is this,
http://localhost:8080/delivery-api/training/submit. It is able to save hard code values into database.
This is part of my html form, it can be open up using this URL: http://localhost:8080/delivery-web/training/apply.
<form th:object="${applyForm}" class="form-horizontal" role="form" method="post" action="http://localhost:8080/delivery-api/training/submit" >
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1" > Country </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" placeholder="Country"
class="col-xs-10 col-sm-7" th:field="*{country}" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Fee </label>
<div class="col-sm-9">
<input type="text" id="form-field-1" th:field="*{Fee}" class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1"> Start Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{startDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right"
for="form-field-1">End Date </label>
<div class="col-sm-9">
<input type="date" id="form-field-1" th:field="*{endDate}"
class="col-xs-10 col-sm-7" />
</div>
</div>
<br> <br>
<button class="btn btn-info" type="submit">
<i class="ace-icon fa fa-check bigger-110"></i> Submit
</button>
</div>
</div>
</form>
When I click on submit, it can be directed to http://localhost:8080/delivery-api/training/submit and insert the hard coded values into database, but it did not direct to my application-form.html page after that.
My controller
#PostMapping(value = "/apply")
public String apply(#Valid #ModelAttribute("applyForm") DeliveryApplicationForm applyForm, BindingResult errors, Model model) {
model.addAttribute("applyForm", applyForm);
return VIEW_PATH + "application-form";
}
I would like to render html page and also pass data from my form to RESTController method through a controller after I click on the submit button in my html page.
May I know how I can do it?

Angular error:Form submission canceled because the form is not connected

What I am trying to do is -
I am trying to add a form to the existing form but the data not getting stored
what the error coming up -
in the console its showing form connection is missing.. how can I connect it with following code I have?
The code behind the click is something like this:
<button type="submit" class="btn btn-default" routerLink="../viewemployee" [disabled]="empForm.invalid">Add Employee</button>
please refer the link below for the code.. need help to move on from this to solve other tasks.
If it is required to post the code here as well, I will do.Please answer and respond.
Thanx in advance.
How to connect the form in angular routing
createemployee.component.html
<h2>Add Employee:</h2>
<form class="form-horizontal" #empForm="ngForm">
<div class="form-group">
<label class="control-label col-sm-2" for="name">Name:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" minlength="4" maxlength="10" pattern="^[A-Za-z0-9]*[A-Za-z0-9][A-Za-z0-9]\S*$" [(ngModel)]="model.name" placeholder="Enter Your Name"
#name="ngModel" required/>
<div *ngIf="name.invalid && (name.dirty || name.touched)" class="alert alert-danger">
<div *ngIf="name.errors.required">
Name is required.
</div>
<div *ngIf="name.errors.pattern">
No Spaces
</div>
<div *ngIf="name.errors.minlength">
Name must be at least 4 characters long.
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="position">Position:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="position" minlength="4" maxlength="10" pattern="^[a-z]*$" [(ngModel)]="model.position" placeholder="Enter your position"
#position="ngModel" required />
<div *ngIf="position.invalid && (position.dirty || position.touched)" class="alert alert-danger">
<div *ngIf="position.errors.required">
Position is required.
</div>
<div *ngIf="position.errors.pattern">
Only Alphabets are must be entered
</div>
<div *ngIf="position.errors.minlength">
Position must be at least 4 characters long.
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="salary">Salary:</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="salary" pattern="[0-9]*"
minlength="5" maxlength="7" [(ngModel)]="model.salary" placeholder="Enter Salary" #salary="ngModel" required />
<div *ngIf="salary.invalid && (salary.dirty || salary.touched)" class="alert alert-danger">
<div *ngIf="salary.errors.required">
Salary is required.
</div>
<div *ngIf="salary.errors.minlength">
Salary must be in 5 numbers.
</div>
<div *ngIf="salary.errors.maxlength">
Salary must not be exceeded morethan 7 numbers.
</div>
<div *ngIf="salary.errors?.pattern">Only numebers should be typed
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default" routerLink="../viewemployee" [disabled]="empForm.invalid">Add Employee</button>
<button type="button" class="btn btn-default" routerLink="../home">Cancel</button>
</div>
</div>
</form>
You could change your component as follows:
Add event handler to the form:
<form (ngSubmit)="continue()">
Handle the routing in code:
continue() {
...
this.router.navigateByUrl("../viewemployee");
}
You need to inject the router:
constructor(private router: Router) {}

Login form using knockout binding doesn't work on Firefox, fine on Chrome

This is utterly bizarre! I have a simple username/password form:
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="LoginUserName" class="col-md-2 control-label">User name</label>
<div class="col-md-10">
<input type="text" id="LoginUserName" class="form-control" data-bind="value: userName, hasFocus: setFocus" />
</div>
</div>
<div class="form-group">
<label for="LoginPassword" class="col-md-2 control-label">Password</label>
<div class="col-md-10">
<input type="password" id="LoginPassword" class="form-control" data-bind="value: password" />
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<div class="checkbox">
<input type="checkbox" id="LoginRememberMe" data-bind="checked: rememberMe" />
<label for="LoginRememberMe">Remember me?</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<button type="submit" class="btn btn-default" data-bind="click: login, disable: session.isBusy()">Log in</button>
</div>
</div>
</form>
First time through, it all works fine and the user is logged in. After logging out and re-entering the user name, the password field is auto-filled. No matter if this is left auto-filled or retyped, when the login method is called, the password field is empty!
If I change the password to an incorrect one it triggers firefox to pop up the "password has changed, do you want to update...?" box at the top of the page. Provided that I answer "yes" to this and then, after that login fails, enter the correct one then it all works and I can log in.
Why on earth is firefox blanking out the password in this circumstance? Completely confused!

HTML form not sending parameters

I wrote a login panel for my website and everything looks fine but when I click on submit page refreshes and no parameters are being sent. I checked both get andpost methods but it's not working. here is my code:
<form id="login_form" action="index.php?task=login" method="post">
<div class="control-group">
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-user"></i></span>
<input class="span2" id="username" type="text" value="Username" onblur="if(this.value=='') this.value='Username'" onfocus="if(this.value=='Username') this.value='';">
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<div class="input-prepend">
<span class="add-on"><i class="icon-cog"></i></span>
<input class="span2" id="password" type="password" value="Password" onblur="if(this.value=='') this.value='Password'" onfocus="if(this.value=='Password') this.value='';" />
</div>
</div>
</div>
<div class="clear"></div>
<div class="separator"></div>
<button type="submit" class="btn">Login</button>
</form>
Can anyone tell me what is wrong with my code?
Your input tags don't have the name attribute which is required to post the value.
<input type="text" name="username" />