How to use variable in value attribute of textarea in Laravel - Blade? - php

I've got the following blade file. I'm passing in a project object with a title and description and I want to populate the value attributes. The description variable works inside the p-tag, but not in the textarea-tag. The $title variable works fine also. Why doesn't it work in the textarea?
#extends('layout')
#section('content')
<h1 class="display-4">Edit Project</h1>
<p>{{ $project->description }}</p>
<form>
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title" placeholder="Title" value="{{ $project->title }}">
</div>
<div class="form-group">
<label for="description">Description</label>
<textarea type="text" class="form-control" name="description" value="{{ $project->description }}"></textarea>
</div>
<button type="submit" class="btn btn-primary">Update Project</button>
</form>
#endsection

There is no value attribute in textarea tag. Instead, put the value between open and close tag:
<textarea type="text" class="form-control" name="description">{{ $project->description }}</textarea>
See this link for more information.

It should be like
<textarea type="text" class="form-control" name="description" >{{ $project->description }}</textarea>

Related

Laravel Form not POSTing

I am trying to make a form do a POST request, however it doesn't seem to be doing it... It comes up with the error
The GET method is not supported for this route. Supported methods: POST.
I'm not really sure why, I've been trying to do some googling but I haven't round anything. Here is my code.
Web.php
Route::post('/admin/products/view/{product}/edit', 'Admin\ProductController#edit')->name('admin.products.edit');
Form
<form method="POST"
action="{{ route('admin.products.edit', ['product' => $product]) }}">
#csrf
<fieldset class="group-select">
<ul>
<li>
<div class="input-box name-firstname">
<label><em class="required">*</em> Title</label>
<input type="text" name="product[title]"
value="{{ $product->title }}" class="input-text required-entry"
required>
</div>
<div class="input-box name-firstname">
<label>Name</label>
<input type="text" name="product[name]" value="{{ $product->name }}"
class="input-text" disabled>
</div>
</li>
<li>
<label><em class="required">*</em> Description</label>
<textarea name="product[description]" class="input-text required-entry"
cols="5" rows="3" required>{{ $product->description }}
</textarea>
</li>
<li>
<label><em class="required">*</em> Allergies</label>
<textarea name="product[allergies]" class="input-text required-entry"
cols="5" rows="3" required>{{ $product->allergies }}
</textarea>
</li>
<li>
<div class="input-box name-firstname">
<label><em class="required">*</em> Price £</label>
<input type="text" name="product[price]"
value="{{ $product->price }}" class="input-text required-entry"
required>
</div>
<div class="input-box name-firstname">
<label>Brand</label>
<select class="custom-select" name="product[name]">
<option selected>Choose...</option>
#foreach($brands as $brand)
<option value="{{$brand->id}}" #if($brand->id ==
$product->brand->id) selected #endif>{{ $brand->name}}
</option>
#endforeach
</select>
</div>
</li>
</ul>
</fieldset>
<div class="buttons-set">
<button type="submit" class="button submit">Save</button>
</div>
</form>
I thought it might be something to do with the route, however even when manually putting the URL into the form it still has the same error. Also when I look at the data being sent its not posting the form data... I'm not sure if this is something to do with my form or maybe the controller. I would love some help on this!
I've found out my problem, by putting on preserve logs and checking the network data I found out that it was redirecting after successfully posting the data. I checked my controller and saw that I'd used the wrong route name and was redirecting it to its self. Thanks for the help everyone :)
Why $product is necessary in the routes whie you're POST'ing the form?

MediumText and textArea in my form show.blade

I need your help because I am stuck... I should create a form with a text long.
In my function up(), I have this
$table->mediumText('resume');
In my page create.blade.php, the create works.
<fieldset class="form-group {{ $errors->has('resume') ? 'has-error' : '' }}">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" id="resume" class="form-control" required="required" value="{{ old('resume')}}"/></textarea>
{!! $errors->first('resume', '<span class="help-block">:message</span>') !!}
</fieldset>
However, I don't get the value (the text) on my page show.blade.php
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true" value="{{$livres->resume}}"/></textarea>
</fieldset>
If I don't use textarea but input type=text it works.
Do you have an idea please?
instead of this
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"
value="{{$livres->resume}}"/></textarea>
</fieldset>
use this
<fieldset class="form-group">
<label for="form-group-input-1">Résumé</label>
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"/>{{$livres->resume}}</textarea>
</fieldset>
Change your code like this (textarea does not get value):
<textarea name="resume" class="form-control" id="form-group-input-1" readonly="true"/>{{$livres->resume}}</textarea>

how can I display saved values from the database to wysiwyg tinymce

Apparently, I can't use
<div>
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description" rows="3" value="{{ $product->description }}"></textarea>
</div>
now that I am using a WYSIWYG(tinymce), it works with textarea alone but with WYSIWYG integrated in a textarea, No. How can I show the value of the description in a WYSIWYG? do I have to use Javascript?
<textarea> doesn't have a value attribute. Put contents between the tags:
<div>
<label for="description">Description</label>
<textarea class="form-control" id="description" name="description" rows="3">
{{ $product->description }}
</textarea>
</div>

Laravel - Get items from session array

I'm making a step program and therefore I wanted to use sessions. I have a form which allows the user to fill in some information and then the input values will be put in a session array called "basic_settins" like this
public function saveSettings(Request $request, Product $products)
{
$request->session()->push('basic_settings', $request->input());
return redirect('/themes');
}
But how can I get a specific item from that array and display it for instance in my view? By using something like this: {{ Session::get('store_name') }} in an input field.
The view looks like this:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-12">
<form method="POST" action="{{ route('saveBasicSettings') }}">
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary mb-3 float-right">Next</button>
</div>
</div>
<div class="card z-depth-2" style="border-radius: 7px;">
<div class="card-body">
<input type="hidden" name="user_id" value="{{ Auth::user()->id }}">
{{ csrf_field() }}
<div class="form-group">
<label for="store_name">Store name</label>
<input type="text" class="form-control" placeholder="Store name" id="store_name" name="store_name" value="{{ Session::get('store_name') }}" required>
</div>
<div class="form-group">
<label for="company name">Company name</label>
<input type="text" class="form-control" placeholder="Company name" id="company_name" name="company_name" value="{{ Session::get('company_name') }}" required>
</div>
<div class="form-group">
<label for="company_tel">Company phonenumber</label>
<input type="text" class="form-control" placeholder="Company Phonenumber" id="company_tel" name="company_tel" value="{{ Session::get('company_tel') }}" required>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
#endsection
When I dd the request by doing this: $data = $request->session()->all(); and then dd($data);
I get the following result:
How can I make this work? Thanks in advance!
When you're using push(), an array will be created, so you need to do something like this:
{{ session('basic_settings.0.company_name') }}
Or:
{{ session('basic_settings')[0]['company_name'] }}
But I would recommend you to save the data with:
{{ session(['basic_settings' => request()->all()]) }}
Then you'll be able to read it with:
{{ session('basic_settings.company_name') }}

How To pre populate Html form field with laravel?

i want to pre fill my html form field "Reference" from url value for referne is afer ref?=1234 how to do it with laravel
<form method="post" accept-charset="utf-8" class="block" enctype="multipart/form-data" action="{{ route('register') }}">
{!! csrf_field() !!}
<div class="row">
<div class="col-md-12 col-sm-12">
<div style="width: 100%" class="alert alert-warning">
Please Register With a Reference User.
</div>
</div>
</div>
<div class="input-group">
<input type="text" name="reference" value="HERE WANT TO SHOW REFEERENCE CODE FROM URL" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-handshake-o"></i></span>
</div>
You can use like:
<input type="text" name="reference" value="{{ app('request')->input('ref') }}" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
Use request() helper:
$ref = request('ref'); // It will return 1234.
There isn't a $GET variable in PHP.
There is a $_GET.
In laravel, you may use the Request facade or Input facade
so here:
<input value="view{{ \Request::get('ref') }}" type="text" name="reference" required class="form-control" placeholder="Enter Reference ID *" aria-describedby="basic-addon1">
// http://localhost/codec/register?ref=g5M089zQeVzc
// will produce
// <input value="viewg5M089zQeVzc" ...

Categories