PHP Laravel Trix wysiwyg how to display content from db - php

Im using laravel 6.0 and have issue with Trix wysiwyg. How to get value to trix editor. The problem is not how to pass it to the view, where I using trix, the problem is how to display it - for example here iam geting content (title) by "value":
Title: </br><input type="text" id='title' name='title' value="{{$article->title}}"></br>
but how to $article->title in Trix, to have chance to edit it? :)
#trix(\App\Article::class, 'title')

just put a value to the hidden input of trix
<input id="short_desc" type="hidden" name="product_short_description" value="{{ $product->product_short_description ?? "" }}" >
<trix-editor input="short_desc" placeholder="Product short description"></trix-editor

Related

How to correctly insert datetime into MYSQL database using HTML form?

I have what seems to be a relatively simple issue that has caused more problems than I thought it would. As you probably know, HTML5 no longer supports the "datetime" input for a form field, and only supports "datetime-local". When I try to insert "datetime-local" into my database through a form on my website, I obviously get an error because of the extra character included in "datetime-local". What I am trying to do, and why I need a datetime field as opposed to just a date and/or time in their own respective fields is because I want to use Carbon to display my datetime in different formats. How can I insert datetime through HTML form into mysql table without manually inserting the value into my database?
EDIT:
Here is all of the relevant code that I am trying to achieve this with. I am using Laravel to build this application
game/create form:
<select name="season_id">
#foreach ($seasons as $season)
<option name="season_id" value="{{ $season->id }}">{{ $season->season }} {{ $season->year }}</option>
#endforeach
</select>
<label for="inputDateTime" class="sr-only">DateTime</label>
<input type="datetime-local" name="gdatetime" id="inputDateTime" class="form-control" placeholder="DateTime" required autofocus>
<label for="inputOpponent" class="sr-only">Opponent</label>
<input type="text" name="opponent" id="inputOpponent" class="form-control" placeholder="Opponent" required autofocus>
<label for="inputLocation" class="sr-only">Location</label>
<input type="text" name="location" id="inputLocation" class="form-control" placeholder="Location" required autofocus>
<label for="inputField" class="sr-only">Field</label>
<input type="text" name="field" id="inputField" class="form-control" placeholder="Field" required autofocus>
game controller:
$game = Game::create(request(['gdatetime', 'opponent', 'location', 'field', 'season_id']));
Also, in my Game model, I have defined this:
protected $dates = ['gdatetime'];
You can always parse your datetime inputs to carbon instance and store them in the database. Parsing will take care of the headache that comes with formatting the input before storing. You can then display them in any format whenever needed.
$date = \Carbon\Carbon::parse($request->input('datetime'));
Edit : Based on your comments and update, do this.
$data = request(['opponent', 'location', 'field', 'season_id']);
$data['gdatetime'] = \Carbon\Carbon::parse(request('gdatetime'));
$game = Game::create($data);
Use PHP to convert it.
date('date format here', strtotime($user_input);
date()
strtotime()
And always be sure to validate user input server side, otherwise strtotime() may return false causing date() to return 1969.
Or you can define this on your model file:
protected $dates = ['your_date_field];
and when you get it from database it will be a Carbon instance.

String display incorrectly when in codeigniter input value using the form helper

I have a strange issue I never had before.
I have a record stored in my database, it is a dutch place name as follow:
's-Heer Abtskerke
if I use the form helper:
<div class="form-group">
<?php
echo form_label('Plaats','plaats');
echo form_error('plaats');
echo form_input('plaats',set_value('plaats',$object->plaats),'class="form-control" id="plaats"');
?>
</div>
I am getting this output:
's-Heer Abtskerke
And if I use the html input element:
<input type="text" name="plaats" class="form-control" id="plaats" value="<?php echo $object->plaats; ?>">
I get the correct output:
's-Heer Abtskerke
I am wondering what is going on in here!
You need to turn off html escape:
set_value('plaats','\'s-Heer Abtskerke', FALSE)
Here you have doc

Laravel Select2 default value

I am using select2 for selection of users, I am populating select2 according to its value in database, I am doing it like this :
<input class="form-control" data-tag-select="director" remote-url="{{ route("query::applies")}}" name="agency_director" type="hidden" value="{{ $team->name }}">
In the value simply i am adding the variable {{ $team->name }} which have the value but nothing comes up.
What am i missing ?

Outputting rows from table in one single text field laravel

Hi gladly I want to put the output of my rows from a table in on single text field. This is what I currently have in my view:
{{Form::label('tag', 'tags')}}
#foreach ($task->tagtask as $tt)
<input type="text" name="tag_name" class="form-control" value='{{ $tt->tag['tag_name'] }}'>
#endforeach
The problem is if I have a task with for example 2 tags. Then its going to loop two times and then I have two textfields with each a value of a single tag. I would like to have one single textfield with all the tags that a task has as a value. But I really don't know how to achieve this.
Can someone help me, please? Gladly I'm waiting for your response. Anyway thanks for your answer.
You can use #foreach inside the value attribute:
{{Form::label('tag', 'tags')}}
<input type="text" name="tag_name" class="form-control" value='#foreach ($task->tagtask as $tt) {{ $tt->tag['tag_name'] }} #endforeach'>
You can always use a little of pure PHP.
{{Form::label('tag', 'tags')}}
<input type="text" name="tag_name" class="form-control" value="<?php foreach($task->tagtask as $tt) echo $tt->tag['tag_name'];?>">

How to use datepicker in Symfony2

I want to add datepicker in my code. I downloaded bootstrap-datepicke. But how add correct this component? I tried something like this
<form action="{{ path('pattient_test') }}" method="post" >
<input type="text" id="pick" value="02/16/12" data-date-format="mm/dd/yy" class="datepicker" >
<input type="submit" value="PrzeĊ›lij zmienione dane"/>
</form>
And then in controller
var_dump( $this->get('request')->request->get('pick'));
But I still get NULL
Try by adding name attribute to your pick input field,
name="pick"
Also,
var_dump( $this->get('request')->request->all()); Allows you to check all POST parameters, it may help you figure out what's going wrong.

Categories