I want users to be able to read and edit their 'About me' text. So far, all works fine, the updated text populates correctly on their profile page. Awesome.
However, I can't get the text to remain in the textform field, which is annoying.
Here's an example of when it does work:
I enable users to update their 'Name' and the name remains viewable in the form.
label for="first_name" class="col-md-4 col-form-label text-md-right">{{ __('First Name') }}</label>
Now, I know that textareas work differently, and I also have a working example where I enable users to update their 'Group Description' and, again, the textarea remains viewable in the form.
<div class="form-group">
<label for="group_description">Group Description:</label>
<textarea class="form-control" rows="5" name="group_description">{{ $group->group_description }}</textarea>
</div>
However, I can't get the 'About me' text to display the textarea?
Here's what I have:
<textarea class="form-control" rows="5" name="about_me">{{ $user->about_me) }}</textarea>
#error('about_me')
I get an error on submission: syntax error, unexpected ')', expecting ',' or ';' (View: -->
The good news is, I can use the below code which does update the 'About me' text, but it will not show the text in the textarea as I need:
<textarea class="form-control #error('about_me') is-invalid #enderror" value="{{ $user->about_me }}" id="about_me" type="text" rows="5" name="about_me" autofocus></textarea>
Theres a wrong format to initialize textarea to display text on it! Here's the code!
<textarea class="form-control #error('about_me') is-invalid #enderror" id="about_me" rows="5" name="about_me" autofocus>{{ $user->about_me }}</textarea>
Related
I have created a custom blog form that uses CKEeditor for submission. By default it inserts <p> tag that my laravel model stores in the db without any issues.
I can view it in my blade files using {!! $variable !!} without any issues. However, when I edit the post the old text doesn't show up in the CKEditor. Without CKEditor I can see the text. E.g. <p> tag shows along with the text. But CkEditor is all blank.
Example Blade Form Code -
<textarea class="ckeditor form-control" name="basics" id="basics" cols="30" rows="10" value="{!! old('basics', $basics) !!}" placeholder="{!! old('basics', $basics) !!}"></textarea>
2nd Attempt:
<textarea class="ckeditor form-control" name="basics" id="basics" cols="30" rows="10" value="{!! $basics !!}" placeholder="{!! $basics !!}"></textarea>
The Last Attempt:
<textarea class="form-control" name="basics" id="basics" cols="30" rows="10" value="{!!html_entity_decode($basics!!}" placeholder="{!!html_entity_decode($basics)!!}"></textarea>
The following worked:
<textarea class="form-control" name="basics" id="basics" cols="30" rows="10" value="basics">{!! $basics!!}</textarea>
in my App I have a table (cats) with 30 categories. The Table "cats" has a name and code field. Every Category needs different forms. To be more flexible and to make the code simpler, I am saving the HTML Code for the different forms directly into the Database.
I am able to fetch the content with:
{!! $cats->code !!}
The Content of the DB Field:
<label for="textfield">Text Field:</label>
<input type="text" name="textfield" id="textfield">
Well, with that simple code, everything runs fine, the HTML Syntax will be shown.
Now I tried with that Code, but this is not working. I think it could be, because I am mixing html with laravel syntax...
<div class="form-group row">
<label for="email" class="col-sm-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="invalid-feedback">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
Has anyone an idea how to solve this issue?
Kind Regards
Stefan
It won't work. Your blade views are parsed to HTML with PHP before any code is run. So Laravel will eventually just echo the blade code, but it is not getting parsed at that stage of your app.
A solution would be to wrap everything in PHP and use eval to have dynamic content stored in the database. This makes it a little bit more of an effort, but it is certainly possible.
I am trying to edit existing post using CKeditor. Content isn't loading.
<div class="form-group">
<label>Content</label>
<textarea id="editor1" name="content" class="form-control" rows="3" placeholder="Enter ...">
{{ Request::old('content') }}
</textarea>
</div>
Also im having trouble getting date from the database too.
<div class="input-group">
<div class="input-group-addon">
<i class="fa fa-calendar"></i>
</div>
<input type="date" name="published_at" class="form-control" value="{{ $post->published_at->format('M jS Y') }}">
</div>
For the textarea, check for old input, but fall back to defaulting to using the model's content attribute (the post's content)
<textarea ....>{!! Request::old('content', $post->content) !!}</textarea>
For your date issue, I don't know what problem you are having.
I have a problem in an application I'm developing, if I have input fields with type 'password' then another input field is populated with data from a completely different element.
If I set the type of the element that is 'password' to 'text' there is no problem.
Unforunatley I can't post an example of jsFiddle, but I've searched around and found other people having a problem with Firefox with an older version.
I'm using version: 43.0b9 with Firebug 2.0.13
IE, Chrome and Safari do not do this with the exact same page loaded, but its very repeatable and very realiable in FireFox.
I've set the attribute autocomplete="off" but no difference.
This problem has me scratching my head...I've commented out just about everything, but the problem still occurs, some how my name and login password are finding there way into two INPUT elements, the same page in Chrome, IE and Safari does not do this.
I was having the same problem, and finally solved it after reading this answer to other similar question: https://stackoverflow.com/a/10745884/6938721
In my case, I had a lot of input fields divided into multiple fieldsets, and sent them through AJAX.
Well, the solution was to surround each <fieldset>...</fieldset> with <form>...</form> labels.
Originally I had something like:
<fieldset>
<input type="text" name="field1">
<input type="password" name="field2">
<input type="password" name="field3">
</fieldset>
<fieldset>
<input type="text" name="field4">
<input type="password" name="field5">
<input type="password" name="field6">
</fieldset>
And after applying the solution I get:
<form>
<fieldset>
<input type="text" name="field1">
<input type="password" name="field2">
<input type="password" name="field3">
</fieldset>
</form>
<form>
<fieldset>
<input type="text" name="field4">
<input type="password" name="field5">
<input type="password" name="field6">
</fieldset>
</form>
Edit:
The key is to not have more than 3 password inputs inside a <form> block. The document works as a <form> block by itself
Hope this helps
I am experiencing that only the Input Textfields respond as expected when I write the code to repopulate a form (when errors were found for example) or when from a table row I click in the Edit button and I go to an editable form. The field for a textarea is not repopulated so it comes up empty, therefore, if I save it, I would delete the content of the textarea. (I know I am asking a succession of questions lately, the reason is that I have basically finished my application and I left for the end the minor things I could not solve, so my apologies for that).
here is an example of what I am saying:
This WORKS for input textfield:
WORKS
<div class="col-md-4">
<label for="relato">Charges</label>
<input type="text" name="expenses" maxlength ="30" class="form-control"
value = "{{ $user->expenses }}"/>
</div>
That is, the $user->expenses fills the textfield of the form that comes up when clicking the Edit button of a table row.
However, that does not work for a textarea field:
<div class="row">
<label for="relato">Description</label>
<textarea name ="message" id="message" rows="5" cols="100" value = "{{ $user->message }} class="form-control"
</textarea>
</div>
See? that part $user->message will not pass the content to the textarea of a form.
Similarly: with Input::old
Works for an Input textfield
WORKS
Email: <input type="text" class="form-control" name="email" {{ (Input::old('email')) ?' value ="' . e(Input::old('email')). '"' : '' }}>
DOES NOT WORK FOR TEXTAREA
<div class="form-group">
<label for="relato">Une petite description</label>
<textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control" {{ (Input::old('content')) ?' value ="' . e(Input::old('content')). '"' : '' }}
">
</textarea>{{ $errors->first('content')}}
</div>
And the controller is also trying to refill the form by sending ->withInput
if($validator->fails()){
return Redirect::route('usersgetformtopostads')
->withErrors($validator)
->withInput();
}
but, as I said, it only works for textfields. Does not repopulate me a select list or a textrarea
By the way, I have looked a related question here where the author says he could not repopulate a File field and he was told that "you cant" and he gave that as a correct answer, however, I have been able to repopulate Files uploaded, not having any problem with that.
textarea does not have a value attribute. Values in textarea should be inside <textarea></textarea>, so in your case:
<textarea id="message" name = "content" rows="10" cols="50" onKeyPress class="form-control">
{{{ Input::old('content') }}}
</textarea>
Just figured it out, put the old value in between the brackets as below
<textarea name="message">{{ old('message') }}</textarea>
This is another way to do the same but with the Forms component from laravel:
{{ Form::textarea('content',Input::old('content'),array('id' => 'message')) }}
I'd like to add one thing, if you use Form Class for the form and elements then you don't need to explicitly right the Input::old('element-name') to retrieve the value of the previous form submission.
Just use
{{ Form::text('name', null, array('id'=>'name', 'class' => 'class-to-apply')) }}
And you're good to go.
Here, null value for the text field will be null for the first time, and if you redirect back this page with input then this will automatically grab the value.
Sorry for late reply
{{Form::textarea('mobile_message', isset($notifications -> mobile_message) ? $notifications -> mobile_message : null, 'id'=> 'mob_id','class' => 'form-control'))}}
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Category Description</label>
<div class="controls">
<textarea style="resize:none" name="category_description" required rows="6">
<div class="control-group hidden-phone">
<label class="control-label" for="textarea2">Category Description</label>
<div class="controls">
<textarea style="resize:none" name="category_description" required rows="6" >{{$category_info->category_description}}</textarea>
</div>
</div>
</textarea>
</div>
Normally, textarea does not have a value attribute, but there's a way you can add that with the current Laravel version (which is 8+)
<textarea>{{{ Request::old('content') }}}</textarea>