Is there a Laravel 5 Form Builder equivalent of HTML 5's datatime input field ? I have been searching all day but could not find any.
<input type="datetime-local" class="form-control" id="game-date-time-text" name="game_date_time">
Any help would be appreciated.
That worked
{{ Form::input('dateTime-local', 'game_date_time', $game->game_date_time, ['id' => 'game-date-time-text', 'class' => 'form-control']) }}
Related
I am trying to list all entries which fall under a where condition. If I do the following, I get all the entries returned
$users = User::lists('userName', 'id');
However, I am looking to return only the users who have a department id of 3. So I am doing
$users = User::lists('userName', 'id')->where('departmentId', 3);
However, this returns an empty result set. In my database, I do have users with this department id.
How can I get the lists statement working?
Just a note, the following returns the result I need
$users = User::select('userName', 'id')->where('departmentId', 3)->get();
However, in my edit form, because I have this
!! Form::select('csManager', $users, Input::old('users'), ['class' => 'csManager']) !!}
The old input is not selected and the data is showing up as an array. I know the way to fix this is to do my select like this
<select class="csManager" name="csManager">
#foreach($users as $user)
<option value="{{ $user->id }}">{{ $user->userName }}</option>
#endforeach
</select>
But then I am not sure how to display the old user within the above select.
Any help appreciated.
Thanks
To mark a old selection try this:
<option value="{{ $user->id }}"
{{ (Input::old('users') == $user->id)? 'selected' : '' }}>
{{ $user->userName }}
</option>
As #TimVanUum say, you can save a little bit of code if you prefer. Both are equals.
<option value="{{ $user->id }}"
{{ (Input::old('users') !== $user->id)?: 'selected'}}>
{{ $user->userName }}
</option>
In your controller:
$users = User::where('departmentId', 3)->lists('userName', 'id');
In blade form:
{!! Form::select('csManager', $users, null, ['class' => 'csManager']) !!}
To get the old data in edit form instead of
{!! Form::open([your attributes]) !!}
Use model binding. something like this:
{!! Form::model($user,[your attributes]) !!}
In this case your edit method should have $user=findOrFail($id);
I wanted put yii2 kartik datetimepicker into a reservation room form, but datepicker doesn´t function.
Im sure , i have use kartik/datetime/DateTimePicker; at the top of code.
This is my code for reservation form. Its not complete, but i want test posting date.
<div class="form-group">
<label> Booked room from </label>
<?php
echo DateTimePicker::widget([
'name' => 'date_in_modal_1',
'options' => ['placeholder' => 'Date and time...'],
'pluginOptions' => ['autoclose' => true]
]);
?>
</div>
<div class="form-group">
<label> Booked room to </label>
<?php
echo DateTimePicker::widget([
'name' => 'date_in_modal_2',
'options' => ['placeholder' => 'Date and time...'],
'pluginOptions' => ['autoclose' => true]
]);
?>
</div>
<input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />
<button type="submit" class="btn btn-primary">Add</button>
I using the same code in index view and this work. The inputs shows, but if i click, the form with date pick and time pick doesn´t show. Can someone help me with this problem?
Thanks u all.
in this form i heve Form::password() and i can not styled or embeded class for that. for example this below class and style for Form::text can work correctly.
{{ Form::text('username', Input::old('username'), array('placeholder'=>'UserName', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="username" class="form-control" type="text" name="username" placeholder="username">
but for Form::password() do not work:
{{ Form::password('password', null, array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
Generated HTML:
<input id="password" type="password" value="" name="password">
This will work:
{{ Form::password('password', array('placeholder'=>'Password', 'class'=>'form-control' ) ) }}
You don't need the null as you cannot specify a default value for password fields.
You can also use a custom HTML macro that enables the syntax similar to your first example.
See my answer here:
How to pass value to Password field in Laravel
This problem occurred when the null value in the password.
{!! Form::password('password', old('password'), ['class' => 'form-control ', 'placeholder' => 'Enter Password']) !!}
Please Remove the old('password'):
{!! Form::password('password', ['class' => 'form-control', 'placeholder' => 'Enter Password']) !!}
how can I send date from my form ?
In previous form I have something like this :
#Html.TextBoxFor(m => m.UserName)
But now I have:
<input type="text" class="form-control" placeholder="Login">
So how I can pass my data ?
I think this is what you are looking for..
<input type="text" class="form-control" value="SOME THING" placeholder="Login">
add an 'id' attribute in your tag, and on postback of your form, you can query the form elements by id. Thats what the MVC code you posted does internally.
I'm using Ruby with the Sinatra framework. I'm sorta new to html. I create a form, and when I look at my #params hash in post, it is a flat hash, as expected:
#params = { input_name_a => user_input_a, input_name_b => user_input_b}
Is there a way to set up some elements of the page to come back as groups, where a key points to an object of key value pairs (which are inputs), instead of a value? So my #params hash would look like this?
#params = { group_a => { input_name_a => user_input_a, input_name_b => user_input_b} }
thanks
<form accept-charset="UTF-8" action="/clients" method="post">
<input type="text" name="client[name]" value="Acme" />
<input type="text" name="client[phone]" value="12345" />
<input type="text" name="client[address][postcode]" value="12345" />
<input type="text" name="client[address][city]" value="Carrot City" />
</form>
When this form is submitted, the value of params[:client] will be {"name" => “Acme”, “phone” => “12345”, “address” => {"postcode" => “12345”, “city” => “Carrot City”}}. Note the nested hash in params[:client][:address].