This is my form:
{{ Form::model($data, array(
'route' => array('waitingtimes.update', $data->id),
'class' => 'mainInformationContrainer',
'method' => 'put'
)) }}
When I submit the form, I got
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
though I've already set the request as put.
Could you help me please?
Edit 1
I noticed that the form html is
<form method="POST" action="http://localhost:8082/test/public/waitingtimes/2" accept-charset="UTF-8" class="mainInformationContrainer">
</form>
It is post not put,
Edit 2
The problem was because I mistyped the route to rout, but not I am getting this exception
Trying to get property of non-object
this is the view:
{{Form::model($data, array(
'route' => array('waitingtimes.update', $data->id)
, 'class' => 'mainInformationContrainer',
'method' => 'put'
))}}
<ul>
<li>
<label>First Time:</label>
<div class="oneInfo">
{{ Form::text('startTime', $value=null, array('class' => 'time ui-timepicker-input', 'id' => 'startTime', 'autocomplete' => 'off'))}}
<span class="errorMessage">
<?php
echo $errors->first('startTime');
?>
</span>
</div>
</li>
<li>
<label>End Time:</label>
<div class="oneInfo">
{{Form::text('endTime', $value=null, array('class' => 'time ui-timepicker-input', 'id' => 'endTime'))}}
<span class="errorMessage">
<?php
echo $errors->first('endTime');
?>
</span>
</div>
</li>
<li>
<label>Value:</label>
<div class="oneInfo">
{{Form::text('value', $value=null, array())}}
<span class="errorMessage">
<?php
echo $errors->first('value');
?>
</span>
</div>
</li>
<li>
<input type="submit" value="Save Changes"/>
<input type="button" value="Cancle" class="cancelButton"/>
</li>
</ul>
{{ Form::close() }}
this is the controller update
$input = Input::all();
$validation = Validator::make($input, WaitingTimes::$rules);
if ($validation->passes()){}else{
return Redirect::route('waitingtimes.edit')->withInput()->withErrors($validation)->with(array(
'verticalMenu'=>'none',
'verticalMenuTab' => 'none',
'data' => $input
));
}
Please notice that this html blade code is used for editing the data and it is working correct when I call the edit function, and I am using it also to redirect when the user try to edit information but the validation falls
You'll need to specify the method in your form creation, add this to your Form::model array:
'method' => 'PUT'
You will need to tell your form that you will be using method PUT:
{{ Form::model($data, array(
'route' => array('waitingtimes.update', $data->id),
'class' => 'mainInformationContrainer',
'method' => 'put',
)) }}
Note that you will still see method = "POST" in your form but Laravel will add a hidden field called _method to your form. See http://laravel.com/docs/html#opening-a-form
I found the solution,
which is
return Redirect::back()->withInput()->withErrors($validation)->with(array(
'verticalMenu'=>'none',
'verticalMenuTab' => 'none',
'data' => $input
));
Thanks to this question
Laravel form model binding
Related
I'm getting the error when I try to create a post and I don't know how to fix it since I just began using laravel and I'm still a noobie.
Route (web.php)
Route::put('/create_action', [App\Http\Controllers\ActionController::class, 'createAction'])->name('auditor.create_action');
This is my controller method:
public function createAction(Request $request) {
$sectors = \DB::table('sector')->get();
$risicosoorten = \DB::table('risicosoort')->get();
$risicoclassificaties = \DB::table('risicoclassificatie')->get();
$users = \DB::table('users')->where('name')->get();
$statussen = \DB::table('status')->get();
return view('auditor.create_action' , [
'sectors' => $sectors,
'risicosoorten' => $risicosoorten,
'risicoclassificaties' => $risicoclassificaties,
'users' => $users,
'statussen' => $statussen
]);
$actie->create([
'create_date' => $req->create_date,
'bron_detail' => $req->bron_detail,
'audit_oordel' => $req->audit_oordel,
'process' => $req->process,
'nummer_bevinding' => $req->nummer_bevinding,
'omschrijving_bevinding' => $req->omschrijving_bevinding,
'probleem' => $req->probleem,
'risico_beschrijving' => $req->risico_beschrijving,
'oorzaak' => $req->oorzaak,
'aanbeveling_ia' => $req->aanbeveling_ia,
'map' => $req->map,
'datum_deadline' => $req->datum_deadline,
'datum_bijgesteld' => $req->datum_bijgesteld,
'datum_gesloten' => $req->datum_gesloten,
'voortgang' => $req->voortgang,
'aantekeningen_ia' => $req->aantekeningen_ia,
'oordeel_ia' => $req->oordeel_ia,
'sector' => $req->sector,
'pr' => $req->pr,
'sr' => $req->sr,
'arc' => $req->arc,
'orc' => $req->orc,
'grc' => $req->grc,
'status' => $req->status,
'sub_status' => $req->sub_status
]);
}
my blade file with the form:
#extends('layouts.master')
#section('title')
#endsection
#section('content')
<div class="create_action" id="post">
<form action="{{ route('auditor.create_action') }}" method="POST">
#method('PUT')
#csrf
<form>
<div class="form-group">
<label for="creation_date">Datum ontstaan actie</label>
<input type="date" class="form-control" name="create_date">
</div>
<div class="form-group">
<label for="bron_detail">Bron detail</label>
<input type="text" class="form-control" name="bron_detail">
</div>
<button type="submit" class="btn btn-primary" name="submitBtn" value="submitPost"><strong>Maak actie aan</strong></button>
#endsection
and wayy more form input fields but trying to keep it as short as possible!
You have two opening form tags in your view. Right after the #csrf directive. Is this intentional? Because you can not nest form tags.
This may be what is causing your error because the application is trying to use the 'Get' method for the inner form tag since no method was stated.
I have created a dev that is changed according to the selected radio button.
the dev has input fields:
<div id='div-cash' class="toHide" hidden="true">
<div class="row" >
<div class="col-md-4">
<?php echo $form->field($cash[0], 'form_get',[
'template' => '{label}<div class="input-group">{input}
<span class="input-group-addon">pt</span></div>{error}{hint}',
'options' => ['class' => 'form-inline toHide cashtoHide', 'style' => 'margin-top:2rem'],
'labelOptions' => ['style' => 'margin-right:2rem'],
])->textInput();?>
</div>
</div>
</div>
when I submit the form the inputs of the other options are validated and I want to disable it
I used Conditional Validation to solve this problem
'whenClient' => "function (attribute, value) {
return $('input[type=radio]:checked').val() == 'cash';
}"
I have checked all similar questions, no one seem to have answered this.
$data = ['data' => array(
['id'=>'1','name'=>'Dupe', 'country' => 'Nigeria'],
['id'=>'3','name'=>'Dipo', 'country' => 'Togo']
)];
$mustache->render('index', $data);
index.html looks like this:
<div>Hello</div>
<br>
<h2>Search for a person</h2>
<form action="/search" method="POST">
Input user's name or email:
<br><input type="text" name="key" value="" required>
<br>
<input type="submit" value="Search">
</form>
{{ #data }}
<div> {{ name }} - {{ country }} </div>
{{ /data }}
It is currently returning a blank page.
I couldn't figure that out, but converting the inner array to objects works just fine:
$m = new Mustache_Engine();
$data = [
'data' => array(
['id' => '1', 'name' => 'Dupe', 'country' => 'Nigeria'],
['id' => '3', 'name' => 'Dipo', 'country' => 'Togo']
)
];
$data = json_decode(json_encode($data));
echo $m->render(
'{{#data}}
<div> {{ name }} - {{ country }} </div>
{{/data}}',
$data
);
This outputs:
<div> Dupe - Nigeria </div>
<div> Dipo - Togo </div>
Notice {{#data}} and {{/data}} have no spaces!
I've used an inline template string as i didn't have yours.
I have a form that I would like a user to fill out with some basic information. However, before submitting the info, I want to include a button I am using to activate Stripe to request payment.
I have tried this so far, however, this button before the submission button is acting as the submit button.
Here is some code:
{{ Form::open(array('route' => 'fans.store')) }}
{{ Form::label('name', 'Name:') }}
{{ Form::text('name', null, array(
'class' => 'input',
));}}
{{ Form::label('email', 'Email:') }}
{{ Form::text('email', null, array(
'class' => 'input',
));}}
<div class="button_row">
<button id="customButton" class="button">Purchase</button>
</div>
<div class="button_row">
{{Form::submit('Submit', ['class' => 'button'])}}
</div>
{{Form::close()}}
Any work arounds? The syntax is blade php (I'm using Laravel 4). Thank you.
Try the following:
{{ Form::button('purchase', 'Purchase with Stripe', array( 'id' => 'purchase', 'onclick'=>'myFunction()')) }}
That creates a purchase button,
labeled "Purchase with Stripe"
Calls myFunction() that launches stripe
<button type="button">
See: http://www.w3schools.com/tags/att_button_type.asp
I have a login form in my header that talks to my users_controller but the form itself isn't in a view being generated by the users controller so I get two problems
1.) The password field doesn't get treat like a password field and is just a normal text field
2.) When submitting the form it just redirects to the login action
Here is the code and it's used in BOTH the login view and in my header (so I know it works):
<?php echo $this->Form->create(null, array('id' => 'loginform', 'type' => 'post',
'url' => array('controller' => 'users', 'action' => 'login'))); ?>
<fieldset id="login">
<ul class="clearfix">
<li id="li-username">
<?php echo $this->Form->input('username', array('label'=>false,'placeholder'=>'Username or email address')); ?>
</li>
<li id="li-password">
<?php echo $this->Form->input('password', array('label'=>false,'placeholder'=>'Password')); ?>
<span id="iforgot"><?php echo $this->Html->link('?',
array('controller' => 'users', 'action' => 'forgotpassword'), array('title' => 'Forgot your password?')); ?></span>
</li>
<li id="li-submit">
<button type="submit" title="Log in">Log in ►</button>
</li>
</ul>
</fieldset>
<?php echo $this->Form->end(); ?>
Why not changing
Form->create(null,...
to
Form->create('User',...
otherwise change
Form->input('username',...
to
Form->input('User.username',...
You can use type = 'password'
echo $this->Form->input('password', array('label'=>false, 'type' => 'password', 'placeholder'=>'Password'));
You have specified array('controller' => 'users', 'action' => 'login') in your $this->Form->create() statement. So the form is submitted to "/users/login"
If you don't want to submit the form to '/users/login', you can use AJAX to perform login.
Hope these will answer your queries.