Display Textbox value in paragraph tag - laravel

I'm sending mail. I'm getting value from textbox, while i send mail i can't get it as paragraph.
For Example:
Textbox value = Hi
I'm Laravel
But in mail inbox = Hi I'm Laravel
Getting Value in Blade:
<textarea style="width: 100%;" name="message" cols="40" rows="10" required></textarea>
In Mail Blade (which display in email inbox):
<p>{{ $message }}</p>

You need to use any text editors like https://www.tiny.cloud/ insted of textarea.
or you need to send the data with html tags

Related

Append data to form using through DOM?

Form which uses POST method:
<div>
<form action="{{ route('post.store') }}" method="POST">
<input type="text" name="name">
<input type="text" name="text">
<button type="submit">Submit</button>
</form>
#foreach ($comments as $comment)
{{ $comment->text }}
Reply
#endforeach
</div>
Array of $comments is being returned when the view itself is returned.
Basically, I am intrested if there is a way to append $comment->id to the data that will be sent to server on Submit button click using Laravel Blade or AlpineJS, but without creating any additional functions between <script> tags? I mean, is it possible to do something like this: Reply?
EDIT:
I expressed myself wrongly. I don't want to append new id every time Reply is clicked, but to overwrite corresponding property in data which is going to be sent to server when Submit button is clicked with the $comment->id for which Reply was clicked for.
I assume you are using Laravel Resource Controller
Not sure I totally understand why you want to send all comment ids when submitting the form but when calling the route post.store you should better send the post id
<form action="{{ route('post.store', ['post' => $post]) }}" method="POST">
If you want to get all comment id and have proper model relationships set up in your models you can get all comments for a post in your controller.
To send a specific id in your form create a new <input name="comment_id" value=""> and let that field be populated.

Laravel validator on a form and send post

I used laravel validator.
I have a form wih 2 fields
If i fill one field "NAME" and i leave the other "SURNAME" empty pressing SAVE button of the form appears required alert message on SURNAME but the name inserted in the NAME field became empty! And i think form send data anyway.why?I aspect that form doesn't send datas
In the value attribute of each input you need to echo old("the-input-name") so it can retain the previous input before the error
<input name="name" value="{{old('name')}}" class="" />
You should use old('NAME') to get the value of the field after the validation fails, blade example:
<input type="text" value="{{ old('NAME') }}" />
An example In case of update forms you should display the original value from the database unless there's an error:
<input type="text" value="{{ old('NAME') ?? $your_entry->value }}" />
Take a look at the documentation for more details

How to display contenteditable contents properly? (laravel) (vue)

I have done saved the contents inside the #descrition below.
<div id="description" contenteditable="true"></div>
My problem is when I try to display it does not display like an html format, it displays same like the saved data with <h1></h1> & <br>. It displays plain text only.
<div id="description" contenteditable="true">{{ $description }}</div>
The content I saved in my database & display:
<h1>Descriptoin</h1> Doner, where I built and maintained banner adverts and microsites. <br> And...
Someone know how to display this properly?
Answer: thanks to #Akram Wahid
In laravel - {!! $description !!}
In vue - <div v-html="description"> </div>
You have to do like this , because Blade {{ }} statements are automatically sent through PHP's htmlspecialchars function to prevent XSS attacks.If you do not want your data to be escaped, you may use the following syntax:
<div id="description" contenteditable="true">{!! $description !!}</div>
By default Laravel escape special characters to prevent XSS attack.
Try using this format:
<div id="description" contenteditable="true">{!! $description !!}</div>

Codeigniter: add a signature to my email

I need to add an image signature in my email body, i write the message into a textarea and the variable $message don't send the image, just send text, and when i use an editable div instead textarea, the message get empty, here my code:
//Controller
$destino = $this->load->view("destino");
$asunto = $this->input->post("asunto");
$mensaje = $this->input->post("mensaje");
$this->email->set_newline("\r\n");
$this->email->from('correopruebas#consultora.cl');
$this->email->to($destino);
$this->email->subject($asunto);
$this->email->message($mensaje);
//view message
<div class="col-md-9" style="float: right;">
<textarea id="editor" name="mensaje">
$this->load->view('firma');
</textarea>
I found the way, just need add other variable $message but in the "=" need to add a dot before ".=", and the path of your signature image on the server:
$message .= '<img src=http://path/to_my/signature.png alt="My Firma"> <br>';

How to update Angular validation messages after $http response?

I'm using Angular $http (http://docs.angularjs.org/api/ng.$http) to submit a form. The server returns JSON:
[{
"hasValidationErrors": true,
"validationErrors": {
"inputNameAttributeValue": "Error Message 1",
"anotehrInputNameAttributeValue": "Error Message 2"
}
}]
Once I receive the JSON response, how do I notify Angular that certain form fields are in an error state so that it automatically changes the view to show error messages?
For example, if I use this markup (from http://www.ng-newsletter.com/posts/validations.html):
<div class="row">
<div class="large-12 columns">
<label>Your name</label>
<input type="text"
placeholder="Name"
name="inputNameAttributeValue"
ng-model="signup.name"
ng-minlength=3
ng-maxlength=20 required />
<div class="error"
ng-show="signup_form.name.$dirty && signup_form.name.$invalid">
<small class="error"
ng-show="signup_form.name.$error.required">
Your name is required.
</small>
<small class="error"
ng-show="signup_form.name.$error.minlength">
Your name is required to be at least 3 characters
</small>
<small class="error"
ng-show="signup_form.name.$error.maxlength">
Your name cannot be longer than 20 characters
</small>
</div>
</div>
</div>
I'm looking for a solution that works with my existing data binding markup in my html doc.
I can change the markup, but I don't want to have two separate sections of markup for each form input (one for client side validation and another for validation after the JSON response).
Update:
For example, if required form fields have not been touched by the user
before the form is submitted, they will not show error messages. So,
my goal is that upon form submission, all form fields are validated
and show validation messages if needed.
That's because ng-show is triggered by both $dirty and $invalid flag.
You can manually set all $dirty of input fields to true when ngSubmit fired.
But, in the case the user has tampered with the form, the JSON
response from the server should be used to add validation messages as
well.
If validation failed on server, just bring these tampered values back to angular models on client and use $apply if needed. AngularJS should do the rest of work.
Simulating example: http://jsfiddle.net/djpV8/4/
Origin:
how about set error messages to the scope and simply display it when it's defined:
scope.errorMessages = returnedJson.validationErrors;
just add a block for displaying custom message from server
<!-- place error messages next to corresponding input fields. -->
<small class="error"
ng-show="errorMessages.inputName"
ng-bind="errorMessages.inputName"></small>

Resources