Laravel 5.4 Class 'form' not found - forms

I'm facing problem 'Class 'form' not found' I'm currently using laravel 5.4. I already have tried maximum efforts to solve.
Thanks
Error is : Whoops, looks like something went wrong.
1/1
FatalErrorException in d0b19e04e5a1f8a5507d8ca427362b23807103ca.php line 23:
Class 'Form' not found
in d0b19e04e5a1f8a5507d8ca427362b23807103ca.php line 23
Here is my Comp
{
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.4"
},
}
I run the composer update command.
Here is my app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
Illuminate\Auth\AuthServiceProvider::class,
Illuminate\Broadcasting\BroadcastServiceProvider::class,
Illuminate\Bus\BusServiceProvider::class,
Illuminate\Cache\CacheServiceProvider::class,
Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
Illuminate\Cookie\CookieServiceProvider::class,
Illuminate\Database\DatabaseServiceProvider::class,
Illuminate\Encryption\EncryptionServiceProvider::class,
Illuminate\Filesystem\FilesystemServiceProvider::class,
Illuminate\Foundation\Providers\FoundationServiceProvider::class,
Illuminate\Hashing\HashServiceProvider::class,
Illuminate\Mail\MailServiceProvider::class,
Illuminate\Notifications\NotificationServiceProvider::class,
Illuminate\Pagination\PaginationServiceProvider::class,
Illuminate\Pipeline\PipelineServiceProvider::class,
Illuminate\Queue\QueueServiceProvider::class,
Illuminate\Redis\RedisServiceProvider::class,
Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
Illuminate\Session\SessionServiceProvider::class,
Illuminate\Translation\TranslationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\Validation\ValidationServiceProvider::class,
Illuminate\View\ViewServiceProvider::class,
'Collective\Html\HtmlServiceProvider',
/*
* Package Service Providers...
*/
Laravel\Tinker\TinkerServiceProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
],
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/
'aliases' => [
'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Notification' => Illuminate\Support\Facades\Notification::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,
'FORM' => 'Collective\Html\FormFacade',
'HTML' => 'Collective\Html\HtmlFacade',
],
];
using form in formupload.blade.php
#if(isset($success))
<div class="alert alert-success"> {{$success}} </div>
#endif
{!! Form::open(['action'=>'ImageController#store', 'files'=>true]) !!}
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('description', 'Description:') !!}
{!! Form::textarea('description', null, ['class'=>'form-control', 'rows'=>5] ) !!}
</div>
<div class="form-group">
{!! Form::label('image', 'Choose an image') !!}
{!! Form::file('image') !!}
</div>
<div class="form-group">
{!! Form::submit('Save', array( 'class'=>'btn btn-danger form-control' )) !!}
</div>
{!! Form::close() !!}
<div class="alert-warning">
#foreach( $errors->all() as $error )
<br> {{ $error }}
#endforeach
</div>
</div>

Put this in composer.json
"require": {
"laravelcollective/html": "^5.4"
},
and Run
composer update
in command afterwards
Or
composer require laravelcollective/html
Then add this in your config/app.php in providers section array
Collective\Html\HtmlServiceProvider::class,
After that add two class aliases in the config/app.php in aliases array
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,

Looks like you set the alias for your Form Class to "FORM" here in your app.php:
'FORM' => 'Collective\Html\FormFacade',
Try changing that to Form like so:
'Form' => 'Collective\Html\FormFacade',
then it should work

run command
composer require laravelcollective/html
when the composer update the require html laravel collective
then add these two line into config/app.php into the section of
'aliases' => [ ],
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
then add the line into config/app.php
'providers' => [ ], and save the file
Collective\Html\HtmlServiceProvider::class,

Run the command
composer require laravelcollective/html
add these two lines into config/app.php into the section of
'aliases' => [ ],
'Form' => Collective\Html\FormFacade::class,
'Html' => Collective\Html\HtmlFacade::class,
add the line into config/app.php
'providers' => [ ], and save the file
Collective\Html\HtmlServiceProvider::class,
this also works for 6.X

class aliases in the config/app.php
'Form' => 'Collective\Html\FormFacade',
this is working for me

Related

Laravel - Route with multiple function

I have a problem with making a page to allow people to edit their profile, the thing is that I have 3 form on one page (one for profile settings, second for social settings and the 3rd for the account settings) and I made 3 controllers to control each one, the problem is that I can't call 3 controllers at the same time for one route...
here is my profile.blade.php:
{!! Form::model($user, ['action' => ['ProfileController#updateProfile', 'id' => $user->id], 'method' => 'PUT']) !!}
...Some input to edit username, name, description settings...
{!! Form:close() !!}
{!! Form::model($user, ['action' => ['ProfileController#updateSocial', 'id' => $user->id], 'method' => 'PUT']) !!}
...Some input to set link to their social account...
{!! Form:close() !!}
{!! Form::model($user, ['action' => ['ProfileController#updateSettings', 'id' => $user->id], 'method' => 'PUT']) !!}
...Some input to update password or email...
{!! Form:close() !!}
Here is my web.php (routes):
Route::get('/profile/{urlid}', 'ProfileController#index')->name('profile');
Route::put('/profile/{urlid}', 'ProfileController#updateProfile');
Route::put('/profile/{urlid}', 'ProfileController#updateSocial');
Route::put('/profile/{urlid}', 'ProfileController#updateSettings');
And here is my ProfileController:
public function updateProfile(Request $request, $urlid)
{
$user = User::findOrFail($urlid);
$user->fname=$request->input('fname');
$user->lname=$request->input('lname');
$user->profile_title=$request->input('profile_title');
$user->profile_resume=$request->input('profile_resume');
$user->save();
return view('profile')->with([
'user' => $user
]);
}
public function updateSocial(Request $request, $urlid)
{
$user = User::findOrFail($urlid);
$user->perso_site=$request->input('perso_site');
$user->linkedin=$request->input('linkedin');
$user->twitter=$request->input('twitter');
$user->save();
return view('profile')->with([
'user' => $user
]);
}
public function updateSettings(Request $request, $urlid)
{
$user = User::findOrFail($urlid);
$user->password=$request->input('password');
$user->email=$request->input('email');
$user->save();
return view('profile')->with([
'user' => $user
]);
}
The thing is that all of those 3 forms are on the same page, and I get an error If I call the 3 functions at the same time
I tried with only one function, it work, everything is ok but with one function, only one form is working, I hope I will find some help, It's been almost 2 hours that I'm blocked with this problem..
So in conclusion: I have 3 forms on the same page, I need these 3 functions to make them work, but I can't call 3 functions for only one route.
Seperate your url's and set your Routes like taht:
Route::get('/profile/{urlid}', 'ProfileController#index')->name('profile');
Route::post('/profile/{urlid}', 'ProfileController#updateProfile')->name('update_profile');
Route::post('/profile/social/{urlid}', 'ProfileController#updateSocial')->name('update_social');
Route::post('/profile/settings/{urlid}', 'ProfileController#updateSettings')->name('update_settings');
and in the form blade use the route function for detting the action url like that ...
{!! Form::open(['url' => route('update_profile', ['urlid' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
...Some input to edit username, name, description settings...
{!! Form:close() !!}
{!! Form::open(['url' => route('update_social', ['urlid' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
...Some input to set link to their social account...
{!! Form:close() !!}
{!! Form::open(['url' => route('update_settings', ['urlid' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
...Some input to update password or email...
{!! Form:close() !!}
You route should looks like
Route::get('/profile/{urlid}', 'ProfileController#index')->name('profile');
Route::post('/profile/{profile_id}', 'ProfileController#updateProfile')->name('update_profile');
Route::post('/profile/{social_id}', 'ProfileController#updateSocial')->name('update_social');
Route::post('/profile/{settings_id}', 'ProfileController#updateSettings')->name('update_settings');
And your form in blade
{!! Form::open(['url' => route('update_profile', ['profile_id' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
//....
{!! Form:close() !!}
{!! Form::open(['url' => route('update_social', ['social_id' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
//....
{!! Form:close() !!}
{!! Form::open(['url' => route('update_settings', ['settings_id' => $user->id]), 'method' => 'post', 'files' => 'true', 'enctype' => "multipart/form-data"]) !!}
//....
{!! Form:close() !!}
In your function
public function updateProfile(Request $request, $urlid)
{
$data = $request->all();
return $data; //check what you pass from the form...
//then after remove return
$user = User::findOrFail($urlid);
if($user)
{
$user->fname=$data['fname'];
$user->lname=$data['lname']
$user->profile_title=$data['profile_title']
$user->profile_resume=$data['profile_resume']
$user->update();
return view('profile')->with([
'user' => $user
]);
}
return "User not found";
}
And the first form for you: https://pastebin.com/JznW20iy
Your second two form: https://pastebin.com/NuDTtvFR
and function
public function updateSocial(Request $request, $urlid)
{
$data = $request->all();
return $data; //check what you pass from the form...
//then after remove return
$user = User::findOrFail($urlid);
if($user)
{
$user->perso_site=$data['perso_site'];
$user->linkedin=$data['linkedin']
$user->twitter=$data['twitter']
$user->update();
return view('profile')->with([
'user' => $user
]);
}
return "User not found";
}
public function updateSettings(Request $request, $urlid)
{
$data = $request->all();
return $data; //check what you pass from the form...
//then after remove return
$user = User::findOrFail($urlid);
if($user)
{
$user->email=$data['email'];
$user->password=$data['newPass']
$user->update();
return view('profile')->with([
'user' => $user
]);
}
return "User not found";
}

Symfony2 - NotBlank constraint not working on EntityType

I have two EntityType fields in my form and both has NotBlank constraint assigned to them.
Now, I have this issue that NotBlank constraint is not working only on one field with multiple => true set on.
$builder
->add('preferredCountries', EntityType::class, array(
'required' => false,
'class' => 'IndexBundle:Country',
'property' => 'name',
'empty_value' => 'Choose',
'multiple' => true,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.name != :name')
->orderBy('c.name', 'ASC')
->setParameter('name', 'Other');
},
'constraints' => array(
new NotBlank(array(
'message' => 'blank!!!',
)),
)
))
->add('internshipProgram', EntityType::class, array(
'required' => false,
'class' => 'IndexBundle:InternshipProgram',
'property' => 'name',
'empty_value' => 'Choose',
'constraints' => array(
new NotBlank(array(
'message' => 'blank!!!',
)),
)
))
In this case when I submit empty values, field internshipProgram get an error, and prefferedCountries not.
Form display:
<div class="form-group col-xs-12">
{{ form_label(current_internship_form.preferredCountries, 'Preferred countries', { 'label_attr': {'class': 'label-text'} }) }}
{{ form_widget(current_internship_form.preferredCountries) }}
<span class="error text-danger small">{{ form_errors(current_internship_form.preferredCountries) }}</span>
</div>
<div class="form-group col-xs-12">
{{ form_label(current_internship_form.internshipProgram, 'What type of training agreement will you have?', { 'label_attr': {'class': 'label-text'} }) }}
{{ form_widget(current_internship_form.internshipProgram, { 'id': 'internship_program', 'attr': {'class': 'form-control '}}) }}
<span class="error text-danger small">{{ form_errors(current_internship_form.internshipProgram) }}</span>
</div>
Is there a mistake in my code or is it somehow related to multiple choice selection? Has anyone had similar issue and know how to solve it?
You can't use NotBlank constraint on EntityType with multiple set to true. As the array will never be null. You should try using the count constraint like this:
$builder
->add('preferredCountries', EntityType::class, array(
'required' => false,
'class' => 'IndexBundle:Country',
'property' => 'name',
'empty_value' => 'Choose',
'multiple' => true,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('c')
->where('c.name != :name')
->orderBy('c.name', 'ASC')
->setParameter('name', 'Other');
},
'constraints' => array(
new Count(array(
'min' => 1,
'minMessage' => "Should not be blank"
))
)
))
...
Also you can specify at Entity level,
/**
* #Count(min = 1, minMessage = "At least one branch must be selected")
*/
protected $multiCheckBox;

Laravel: Form select not working with style / class when setting the default option

I am using Laravel 5 with Bootstrap.
When I use below, the class and/or style works fine:
{!! Form::select('mylist', [''=>'-- select --'], array('id' => 'mylist'), array('class' => 'myclass', 'style' => 'width:116px)) !!}
However, when I set $mylist as the default option for my select form (in my edit record page), the style / class is not working:
{!! Form::select('mylist', [''=>'-- select --'] + $mylist, $row->myfile, array('id' => 'mylist'), array('class' => 'myclass', 'style' => 'width:116px)) !!}
Please kindly advise me to achieve this.
Thanks,
Naren
I think this is the correct format you should use
{!! Form::select('mylist', $mylist, $row->myfile, array('placeholder' => 'Select','class' => 'myclass', 'style' => 'width:116px')) !!}

Create a SelectBox using Form Helper in CakePHP3

I am trying to make a combo box for an edit page.
echo $this->Form->select('status',
['empty' => 'Select Status'],
['class' => 'form-control', 'required']
);
Here I want to add 2 things :
$options = array('0' => 'Inactive',
'1' => 'Active',
);
and selected value. suppose that is $status;
I tried with different options but sometime it do not add classes and sometime it shows options in tag
It will be great if somebody give clue.
Thanks
<?= $this->Form->input('status', [
'type' => 'select',
'options' => ['0' => __('Inactive') , '1' => __('Active')],
'empty' => __('Select Status'),
'class' => 'form-control',
'required' => true, 'label' => __('Type')
])
?>

Yii2 Modal Dialog on Gridview update button not load the update form

With reference to How to implement Yii2 Modal Dialog on Gridview view and update button?. I did my code below, but it popups a window with no update form. could anyone please let me know the correct code? (i use Kartik Gridview)
This is the code for column:
['class' => '\kartik\grid\ActionColumn',
'template'=>'{update}{delete}{view}',//{view}'//{view}{delete}',
'headerOptions' => ['width' => '20%', 'class' => 'activity- update-link',],
'contentOptions' => ['class' => 'padding-left-5px'],
'buttons' => [
'update' => function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-pencil"></span>','/projects/update?id='.$key.'', [
'class' => 'activity-update-link',
'title' => Yii::t('yii', 'Project Update'),
'data-toggle' => 'modal',
'data-target' => '#activity-modal',
'data-id' => $key,
'data-pjax' => '0',
]);
},
],
],
This is JS code:
<?php $this->registerJs(
'
function init_click_handlers(){
$(".activity-update-link").click(function(e) {
var fID = $(this).closest("tr").data("key");
$.get(
"update",
{
id: fID
},
function (data)
{
$("#activity-modal").find(".modal-body").html(data);
$(".modal-body").html(data);
$("#activity-modal").modal("show");
}
);
});
}
init_click_handlers(); //first run
$("#project_pjax_id").on("pjax:success", function() {
init_click_handlers(); //reactivate links in grid after pjax update
});
');
?>
<?php
Modal::begin([
'id' => 'activity-modal',
'header' => '<h4 class="modal-title">Update Project Testing</h4>',
'size'=>'modal-lg',
'footer' => '<a href="#" class="btn btn-primary" data-
dismiss="modal">Close</a>',
]); ?>
<div class='well'></div>
<?php Modal::end(); ?>
Thanks all for watching my question. I solved my issue by adding modal into main.js file of the assets folder using class instead of ID.