Laravel 4.2 Blade submit with class won't work - laravel-4

I have this submit form does not work
{{ Form::submit('REGISTRO', ['class' => 'btn waves-effect waves-light btnenviar cerrarmegamenu']) }}
but if I delete classes and styles it works
{{ Form::submit('REGISTRO') }}
what am I doing wrong?

Related

{!! Html::style('css/parsley.css') !!} NOT WORKING

I'm new to Laravel and I also understand that Laravel has stopped supporting Collective but I managed to still install the package into my Laravel 5.8 project.
Now my problem is, when I tried adding the line below, it does not work. When I inspect element, it's not showing in the head section of the page.
{!! Html::style('css/parsley.css') !!}
Do you think it has something to do with the fact that Laravel no longer supports Collective or I'm doing something wrong here?
Thank you so much for your help guys!
I also tried using
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
BUT STILL NOT WORKING.
This is the code of the whole page I'm working on.
#extends('main')
#section('title', '| New Post')
#section('stylesheets')
{{-- {!! Html::style('css/parsley.css') !!} --}}
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
#endsection
#section('content')
<div class="jumbotron">
<div class="container">
<h1 class="display-4">Create New Post</h1>
<p class="lead"></p>
<hr class="my-4">
<p>Fill out the fields to write your post.</p>
{{-- <a class="btn btn-primary btn-lg" href="#" role="button">Learn more</a> --}}
</div>
</div>
<div class="container">
<div class="col-sm-12 col-md-12">
{!! Form::open(array('route' => 'posts.store', 'data-parsly-validate' => '')) !!}
{{ Form::label('title', 'Title:') }}
{{ Form::text('title', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::label('body', 'Body:') }}
{{ Form::textarea('body', null, array('class' => 'form-control', 'required' => '')) }}
{{ Form::submit('Create Post', array('class' => 'btn btn-success btn-lg btn-block mt-2')) }}
{!! Form::close() !!}
</div>
</div>
#endsection
#section('scripts')
{!! Html::script('js/parsley.min.js') !!}
#endsection
I expected the parsley.css and parsley.min.js be imported into the page but it didn't work.
How does your template looks like? Do you have a #yield('stylesheets') in your template?
Where is your parsley.css located?
I fixed the problem. I had to remove the Collective codes and back to basic to make it work.

Changing laravel form to html form

Hi i created a form with laravel form helpers but i want to change it to a standard html form. The issue i am having is with the "PUT" function, when i try to edit my posts no data is displayed so i think my form properties are wrong.
Form header
<form method="post" action="{{route('posts.update',[$post->id])}}" enctype="multipart/form-data">
{{csrf_field()}}
{{method_field('put')}}
<input type=""text" name="name" class="name">
<input type=""text" name="body" class="body">
<button></button>
</form>
(--UPDATED--)
Laravel Form
{!! Form::model($post, ['route' => ['posts.update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, ["class" => 'form-control input-lg']) }}
{ Form::label('body', 'Body:') }}
{{ Form::text('body', null, ["class" => 'form-control input-lg']) }}
{{ Form::submit('Save Changes', array('class' => 'btn btn-success btn-block')) }}
{{ Form::close() }}
I want the blog data to be displayed in the form for me to edit.. When i use form helpers it works fine
Any help will be much appreciated
Thanks
Ash
Ash,
I don't see the Laravel form code here to compare the two, but the easiest way to convert the Laravel form to straight HTML is to view source on the generated form and copy the generated HTML code back into the blade. Then you can replace populated data with variables.
(--UPDATED--)
Hence, put this back into your blade:
{!! Form::model($post, ['route' => ['posts.update', $post->id], 'method' => 'PUT']) !!}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, ["class" => 'form-control input-lg']) }}
{ Form::label('body', 'Body:') }}
{{ Form::text('body', null, ["class" => 'form-control input-lg']) }}
{{ Form::submit('Save Changes', array('class' => 'btn btn-success btn-block')) }}
{{ Form::close() }}
and then copy the HTML output for the "put" action. Or, if you're on the current version of Laravel, you can simply use the put method as follows:
#method('PUT')
(see https://laravel.com/docs/5.8/blade)
(--ORIGINAL--)
Also, you didn't mention what version of Laravel you're on. The syntax for inserting fields into the blade varies.
(--UPDATED--)
#kapitan, you're right. I "learned" that from using LaraShift telling me that all my {{ $field }} needed to be changed to {!! $field !!} to upgrade my app. The syntax has changed as follows.
In older versions of Laravel, variables inserted with {{ $field }} were UNescaped, and variables inserted with {{{ $field }}} were escaped.
In newer versions of Laravel, variables inserted with {{ $field }} are escaped, and variables inserted with {!! $field !!} are UNescaped. So the meaning of {{ $field }} has reversed from older versions to newer versions.

Select box in form blade Laravel

how can I create a select box which is filled with values from the db?
The view is published with the $groups variable. In my select box i need $groups->id (hidden, only for storing) and $groups->name. This is currently my form.
{!! Form::open(array('route'=>'store.invitation')) !!}
<div class="form-group">
{{Form::label('username', 'Username')}}
{{Form::text('username', '', ['class' => 'form-control', 'placeholder' => 'Enter Username'])}}
{{Form::label('groupname', 'Gruppe')}}
{{Form::select($groups->name) }}
{{ csrf_field() }}
</div>
<div>
{{Form::submit('Submit',['class' => 'btn btn-primary'])}}
<a class="btn btn-default btn-close" href="{{ route('home') }}">Cancel</a>
</div>
{!! Form::close() !!}
Thanks
You should pass an array of the data that you get from the db. Like this:
Form::select('size', array('L' => 'Large', 'S' => 'Small'));
This documentation might be old, but thats how you can create Form::select in blade.

Laravel checkbox $request issue

I am trying to pass 2 array of checkboxes, to my controller: roles and permissions to insert and/or patch in DB.
in my controller I am passing the collections to display on blade:
$roles = Role::all();
$permissions = Permission::all();
and all works fine as it displays the name and the checkbox.
Yet 2 issues when submitting:
$request is showing a simple array for each without the name of the role/permission.
I do not get an "off" for non checked.
http://prntscr.com/jq61p6
I am expecting to insert/patch roles and permissions for a specific $user->id.
I am assuming the problem is in blade and in my checkbox inputs:
<form method="POST" action="{{ route('roles-permissions',['id' =>$user->id]) }}">
{{ csrf_field() }}
<h5>User Roles</h5>
<div class="col-xs-12">
#foreach ($roles as $role)
{{ Form::checkbox('roles[]', null, true, ['class' => 'name'] ) }}
{{ Form::label($role->name, ucfirst($role->name)) }}<br>
#endforeach
</div>
<div class="break-20"></div>
<h5>User Permissions</h5>
<div class="col-xs-12">
#foreach ($permissions as $permission)
{{ Form::checkbox('permissions[]', null , false, ['class' => 'name']) }}
{{ Form::label($permission->name, ucfirst($permission->name)) }}<br>
#endforeach
</div>
{!! Form::submit('Save Roles and Permissions', ['class=', '"btn btn-primary width-250 mt-20"']); !!}
</form>
How can I fix this so I can see the role and permission name so I can pick up the right permissions/roles by my controller and save them into my roles/user and permissions/user tables?
Thanks.
3rd argument will decide whether it will be checked or not. Use null instead of true & let's check whether it works or not.

Resizing checkbox in form group in Laravel

<div class="col-md-3">
<div class="white-box">
{{ Form::open(['route' => ['resources.select'], 'method' => 'ANY', 'role' => 'select']) }}
<div class="form-group">
{{ Form::label('category_label', 'Categories : ') }}
{{ Form::select('category_select', $category_select, ['class'=>'form-control']) }}
{{ Form::button('Submit',['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id'=>'select_resource']) }}
</div>
{{ Form::close() }}
</div>
</div>
This is my code. I have three different divisions that look the same. When I tried to change to a grid view, The select boxes stay overlapping the div block.
I want them to stay within the block in the view.
The reason why your select is overlapping is because you are missing null as a parameter in the declaration.
Change this line;
{{ Form::select('category_select', $category_select, ['class'=>'form-control']) }}
to this;
{{ Form::select('category_select', $category_select, null, ['class'=>'form-control']) }}
Also you do not need the to style the form. A more efficient way of creating the form in your question would be like the example below
<div class="col-md-3">
<div class="white-box">
{{ Form::open(['route' => ['resources.select'], 'method' => 'ANY', 'role' => 'select']) }}
<div class="form-group">
{{ Form::label('category_label', 'Categories : ') }}
{{ Form::select('category_select', $category_select, null, ['class'=>'form-control']) }}
</div>
{{ Form::button('Submit',['type'=>'submit','class'=>'btn btn-success waves-effect waves-light m-r-10', 'id'=>'select_resource']) }}
{{ Form::close() }}
</div>
</div>

Resources