Hi im using ckeditor so i currently have the html version which is
<textarea class="ckeditor" name="editor" id = "stuff">
{{ $opendoc }}
</textarea>
the $opendoc came from my controller. it contains txt in my controller it looks like this
$fname = $file->filename;
$opendoc = file_get_contents(public_path('uploads/docs/' . $fname));
return View::make('dmy.open_doc' , compact('title', 'smpl' , 'opendoc'));
im trying to display the data using laravel 4.2 textarea
currently im using something like this
{{ Form::textarea('open_file', $opendoc , array('class' => 'ckeditor')) }}
but the value of $opendoccould not be viewed. any ideas what im doing wrong? thanks in advance
It just shows the textarea but without any contents - check whether that variable is set or not.
{!! Form::textarea('open_file', isset($opendoc)? $opendoc:null, array('class' => 'ckeditor','size' => '10x3')) !!}
Use the Form::textarea() method.
The simplest usage is to only pass a single argument, the name.
{{ Form::textarea('notes') }}
This produces the following HTML.
<textarea name="notes" cols="50" rows="10"></textarea>
Notice the default cols and rows.
You can pass the value as the second argument.
{{ Form::textarea('notes', '3 < 4') }}
The value will be escaped.
<textarea name="notes" cols="50" rows="10">3 < 4</textarea>
Additional options can be passed as a third argument. This must be an array.
{{ Form::textarea('notes', null, ['class' => 'field']) }}
This will add the class "field" to the text area.
Your solution
{!! Form::textarea('open_file', isset($opendoc)? $opendoc:null, array('class' => 'ckeditor','size' => '10x3')) !!}
Related
I have an edit view and i am using a partial _form view.
Is there a way to check if the form is a patch or post?
What i plan to do is to change the hidden field in edit form
#if (form is post)
{!! Form::hidden('signature') !!}
#else
<div class="form-group">
{!! Form::label('signature', 'Signature: ', ['class' => 'col-md-4 control-label']) !!}
<div class="col-md-6">
{!! Form::text('signature', null, ['class' => 'col-md-2 form-control', 'required']) !!}
</div>
</div>
#endif
because this variable is already saved to DB and i want to load it for edit.
Or to check if form is post, that would work also!
I usually pass the variable to a view where I set action, like:
$action = 'store';
Then I use this variable to build route name:
{!! Form::open(['route' => 'post'.$action, ....
And detect what type of action is needed:
#if ($action == 'store')
I guess it's the most readable and simple way to achieve what you're trying to achieve. You can do something similar.
Try this:
$isPut= Request::isMethod('put');
if($isPut) {
//
}
I have the following form :
{!! Form::open(['action' => 'PublicController#showProfile','method' => 'post', 'class' => 'form-horizontal']) !!}
{!! Form::token(); !!}
<input type="text" class="form-control" name="from">
<span class="input-group-addon"> to </span>
<input type="text" class="form-control" name="to">
<button type="submit" class="btn blue">Query</button>
{!! Form::close() !!}
In my controller I am getting the form fields like this :
public function showProfile(Request $request)
{
$to = $request->get("to");
$from = $request->get("from");
$giftReceived = App\GiftSent::whereBetween('created_at', [$from, $to])->get();
dd($from);
return view('user.profile',compact('giftReceived'));
}
In the above code dd($from) comes null
Am i missing something ?
First of all, as stated in your comments, you are using Route::get and submitting the form as POST which is obviously wrong. So, you should probably get MethodNotAllowedException
So, kindly change the line to
{!! Form::open(['action' => 'PublicController#showProfile','method' => 'GET', 'class' => 'form-horizontal']) !!}
In any case, instead of using Laravel's Request Class, prefer using the helper function request()
So, basically, it should be like
public function showProfile() {
$from = request()->get('from');
$to = request()->get('to');
dd($from, $to);
}
Everything should work fine now :)
If your post data is sending to controller, you can access the values like:
// Get all request data via method POST.
$requestData = Request::instance()->request->all();
dd($requestData['from']);
dd($requestData['to']);
I have a slight problem. I have a system whereby I can drag and drop my own forms. The html code for a form is saved in my database. When it comes to the edit page, I do something like the following
{!! Form::model($project->document, [
'class'=>'form-horizontal',
'method' => 'PATCH',
'route' => ['projects.documents.update', $project, $document->id]
]) !!}
{!! $documentData->documentData !!}
<div class="form-group">
{!! Form::submit('Save Data', ['class' => 'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
$documentData->documentData contains the html code for this particular form.
Now my problem is, $documentData->form_data contains the old inputs for this form.
Is there any way to get this old input into the form, the way I am currently handling things?
Thanks
in controller you can access old input by $request->flash(); while in frontend you can access old by input type="text" name="name" value="{{ $name }}"
I have a text box that needs to be made readonly; I don't want to use array('disabled' => 'true') because I need PHP to process the field:
{{ Form::text('login_token', Worker::generateLoginToken()) }}
How do you add this attribute?
Just add it as the 3rd argument:
{{ Form::text('login_token', Worker::generateLoginToken(), ['readonly']) }}
That's how I did it in Laravel 5:
{!! Form::text('id', null, ['class' => 'form-control', 'readonly' => 'true']) !!}
Cheers.
Write the following line
{!! Form::text('field_name','field_value',array('class'=>'form-control','readonly')) !!}
For Laravel 5 and above
{!! Form::text('name', 'default-value', ['class'=>'class-name','readonly']) !!}
In third argument you can pass all your extra arguments in form of an array. This line will result into something like this in html.
<input class="class-name" readonly="readonly" name="name" type="text" value="default-value">
For Laravel < 5 , this should work
{{ Form::text('name', 'default-value', ['class'=>'class-name','readonly']) }}
Try this...
{{ Form::text('login_token', Worker::generateLoginToken(),array('readonly')) }}
I am using Laravel 5.4 along with BootForm, and the only way that it has worked was by doing:
{!! BootForm::text('Name', 'name', $name)->disable() !!}
Based on the docs of adamwathan/form.
Hope it helps!
Inside a Laravel4 + Bootstrap 2.3.1 I have a form properly working with validation.
There are three fields obligatory: Name - Email - Phone.
When nothing is inserted, or the email is not in a proper format, the error messages are displayed.
But besides this, I would like to make the fields red, to show better where the error is.
How can I do this in Laravel + Bootstrap?
This is the form with the three fields obligatory:
<form name="room" method="post" class="narrow_width">
<label><span><i class="icon-user"></i></span> Name <span class="color-red">*</span></label>
{{ Form::text('name',Input::old('name'), array('class' => 'span7 border-radius-none')) }}
<label><span><i class="icon-envelope-alt"></i></span> Email <span class="color-red">*</span></label>
{{ Form::text('email',Input::old('email'), array('class' => 'span7 border-radius-none')) }}
<label><span><i class="icon-phone"></i></span> Phone number <span class="color-red">*</span></label>
{{ Form::text('phone',Input::old('phone'), array('class' => 'span7 border-radius-none')) }}
<p><button type="submit" name="submit" class="btn-u">Send Message</button></p>
</form>
Thank you very much!
I don't think there's an easy way to do this with the laravel Form class. I personally use my own package https://github.com/AndreasHeiberg/theme for this. You can use it if you wan't but it's subject to change.
Anyway raw code to do this is the following:
<div class="control-group {{ $errors->has($id) ? 'error' : false }}">
<label for="{{ $id }}" class="control-label">{{ $text }} {{ $required ? '<span class="required-red">*</span>' : ''}}</label>
<div class="controls">
<input type="{{ $type }}" id="{{ $id }}" name="{{ $id }}" value="{{ $value }}">
#if ($helpText)
<span class='help-inline'>{{ $helpText }}</span>
#endif
#foreach($errors->get($id) as $message)
<span class='help-inline'>{{ $message }}</span>
#endforeach
</div>
</div>
This being the important part
<div class="control-group {{ $errors->has($id) ? 'error' : false }}">
You can wrap this up in a form macro http://laravel.com/docs/html#custom-macros use a helper function or my package to do this.
With my package you would just use:
+#formText('name')
You can easily use Form macros, there is a bunch available here for Bootstrap 3:
http://forums.laravel.io/viewtopic.php?id=11960
Hope this helps...
Thanks for your efforts, especially #AndHeiberg.
For reason of simplicity, i decide to renounce to Laravel-Bootstrap validation and use instead a jquery plugin: https://github.com/jzaefferer/jquery-validation
The main reason is that is extremely easy to use.
It's enough to call the plugin and insert 'required' into the tag.
And the plugin will do all the rest, highlighting the field in red and displaying an error message for that field.
If your intention is to make the error more obvious to where it is, you can wrap the message text that is returned from Laravel validation errors in a span and give styling to that.
{{ $errors->first('email', "<span class='error'>:message</span>")}}
where :message is a "placeholder" for your error message. And then you can give any styling to .error spans as you wish. Check this Laracast lesson for more details (after 3:10).
In bootstrap, you can create errorfield with the id "inputError":
<input type="text" class="form-control" id="inputError">