Using HTML Placeholder in Laravel 4 - laravel

{{ Form::text('username', Input::old('username')) }}
This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.
I tried to use the example
{{ Form::text('username', 'Username', Input::old('username')) }}
But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.

{{ Form::text('username', Input::old('username'), array('placeholder'=>'Username')) }}
This works for Laravel 4!!

{{ Form::text('username', null, array('placeholder'=>'Username' )); }}

Use:
{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}

Been a while since this was updated but with Former for Laravel the way to do this would be:
Former::text('field')->placeholder('langfile.path.to.placeholder.text')))
The lang file would be called langfile.php with the array containing:
<?php
return array (
'path.to.placeholder.text' => 'Some Placeholder Text.'
);

In case somebody wonders how this should work for a password field:
{{ Form::password('password', array('placeholder'=>'Password')) }}

Related

Laravel collective select placeholder not working when multiple is to true {{ Form::select() }}

I have a problem with Laravel collective select placeholder not working
{{ Form::select('album',$albums,$selected, ['class'=>'form-control','placeholder'=>'select album' ]) }}
But when i allow tags to true like this using select 2, it works fine,
{{ Form::select('tags[]',$tags,$tagged, ['data-input'=>'select2-tags','multiple'=>true]) }}
The second one works fine, I don't want the album to have multiple input attribute, What am i doing wrong?
You can do this with select, but you can add placeholder as the value with 0 index:
$albums[0] = 'select album';
Alternatively, you can create your own select function using Laravel Collective Form macros.
You can follow this :
{{ Form::select('album', $album , Input::old('album'), array('placeholder' => 'Please select','class'=>'form-control')) }}

About Laravel - How to use function string in view

i try to to show data from database article...the content is contain html tags and long text..
so i want make a read more and convert tag html to html view..
this is my code is run :
{{ HTML::decode($show->content) }}
{{ str_limit($show->content, $limit=100, $end=' ...') }}
i try this :
{{ HTML::decode(str_limit($show->content,$limit=100, $end=' ...')) }}
{{ str_limit(HTML::decode($show->content),$limit=100, $end=' ...') }}
but not show ( blank )
annyone can help me to fix it??
thank u b4
Is {{ $show->content }} returning any data to format?
Is your template is .blade?
Maybe it placed somewhere in HTML, where it is not visible?
Try to use this construction with some predefined string to find out if it works. Here is working example:
{{ str_limit('Some big text', $limit = 5, $end='...') }}

Laravel update via form model binding

I have a little web app in which users can register, if they want to update their accounts later then a form is shown with all their info. via form model binding. I they save it and the username isn't changed, a problem occurs because in the validation it must be unique but it already exists (of course, they are updating, not creating). What would you do to avoid this problem?
Can you please share your code?
Normally here is what the code should look like.
{{ Form::model($user, array('route' => 'user.edit', $user->id)) }}
<!-- name -->
{{ Form::label('Full Name', 'Full Name') }}
{{ Form::text('Full Name') }}
<!-- email -->
{{ Form::label('emailAddress', 'emailAddress') }}
{{ Form::email('emailAddress') }}
{{ Form::submit('Update') }}
{{ Form::close() }}
I'd recommend not binding username in your form or making it read only. I assume you will be storing user id or username in session anyway.

How to add a tag (span, small) to Laravel Form::label?

In Laravel 4.1, I want to echo:
<label for="name">Name <small>required</small></label>
This doesn't work:
{{ Form::label('name','Name <small>required</small>') }}
are automatically converted to code text…
Is there a way or do I have to skip Form::label and do it manually?
If you want to use a Html tag inside another by Laravel one you should use HTML::decode.
Correct code :
{{ HTML::decode(Form::label('name','Name <small>required</small>')) }}
Try this:
{!! Html::decode(Form::label('name','Name <small>required</small>')) !!}

Using Laravel Form class to add the 'disabled' attribute

Using Laravel 4's Form class, we can create a list using
{{ #Form::select('colors', Colors::all()), $color }}
Question: How can we add the attribute disabled using Blade without having to rewrite the clean Blade syntax into the usual ugly form?
Just add array('disabled') in the end like:
{{ Form::select('colors', Colors::all(), $color, array('disabled')) }}
This should do the work.
{{ #Form::select('colors', Colors::all()), array(
'disabled' => 'disabled',
'class' => 'myclass'
) }}
Though already answered, IMO both answers weren't neutral enough, so to avoid duplicates the arguments are
#Form::select('name', $optionsArray, $selectedOption, ['disabled']).
So if you're prepopulating form with #Form::model() you should do #Form::select('name', $optionsArray, null, ['disabled']) - array with 'disabled' has to be 4th parameter.

Resources