Codeigniter, when I try to update, the single quote displays as ' - codeigniter-3

I like set_value. Every time, when I try to update the post, the single quote displays as &#039 ;. Not only single quote, some characters display too. Please, help me
Im using Codeigniter 3, Php 7
View
$description = array(
'name' => 'description',
'type' => 'text',
'placeholder' => 'description',
'class' => 'form-control',
'rows' => '3',
'value' => set_value('description', $post->INTRO_DESCRIPTION),
);
<div class="form-group">
<label for="description" class="col-md-2 control-label">Details</label>
<div class="col-md-10"><?php echo form_textarea($description); ?></div>
<div class="col-md-10"><?php echo form_error('description', '<div class="text-danger">', '</div>'); ?></div>
</div>

Well I found the solution. And it's very simple. Just adding "false" at end of the set_value.
set_value('description', $post->INTRO_DESCRIPTION, FALSE)

Related

Symfony 3+ : Styling the parent div of a field (div containing label + input)

At first, my objective here is to make two input fields inline, the picture is attached :
Symfony allow us to style form's field by using attr for form_widget of the field and label_attr for form_label but here i want to apply a style for the div containing the label + input that Symfony generate automatically in the twig :
$builder
->add('language', ChoiceType::class, array(
'choices' => array(
'FR' => 5,
'EN' => 1,
),
'label' => ' ',
'attr' => array('style' => 'float:left;width:40%'),
))
->add('level', ChoiceType::class, array(
'choices' => array(
'Good' => 5,
'Bad' => 1,
),
'label' => ' ',
'attr' => array('style' => 'float:left;width:40%'),
));
result : The style has been applyed to the input (select in our case) and the div parent wasn't be affected (stay with empty style):
<div id="homebundle_personnel_personnelLanguages_0">
<div> <!-- the div that i want to apply a style -->
<label for="homebundle_personnel_personnelLanguages_0_language" class="required"> </label>
<select id="homebundle_personnel_personnelLanguages_0_language" name="homebundle_personnel[personnelLanguages][0][language]" style="float:left;width:40%">
<option value="5">FR</option>
<option value="1">EN</option>
</select>
</div>
<div>
<label for="homebundle_personnel_personnelLanguages_0_level" class="required"> </label>
<select id="homebundle_personnel_personnelLanguages_0_level" name="homebundle_personnel[personnelLanguages][0][level]" style="float:left;width:40%">
<option value="5">Good</option>
<option value="1">Bad</option>
</select>
</div>
</div>
Resolved, I must treat this in the twig's level :
<div style="float:left;width:40%" >
{{ form_widget(form.language) }}
</div>
<div style="float:left;width:40%" >
{{ form_widget(form.level) }}
</div>
use:
'row_attr' => [
'class' => 'yourClass',
],

Cakephp Email format validation before submit the form

I need to validate the Email format before submitting the form in Cakephp.
I was provided an invalid email (i.e. testuser1 instead of testuser1#domain.com). The request was submitted, then got error. If email is invalid, request should not be submitted.
Very curious about what I missed in my code and also referred related questions in forum but that was not work for me. H
Code is:
//for email input
<div class="form-group">
<?= $this->Form->label("email", __('Email')); ?>
<?= $this->Form->text("email", [
'required' => true,
'label' => false,
'id' => "email",]);
?>
</div>
<div class="btn-group btn-group-spaced form-group" role="group" aria-label="Actions">
<?= $this->Form->button(__('Submit'), ['class' => 'btn orange btn-default']) ?>
<?= $this->Form->button(__('Clear'), ['class' => 'btn orange hollow btn-default ucase','id' => 'show-prof','type' => 'reset']) ?>
</div>
Try:
//for email input
<div class="form-group">
<?= $this->Form->label("email", __('Email')); ?>
<?= $this->Form->input("email", [
'required' => true,
'label' => false,
'id' => "email",
'type' => "email"
]);
?>
</div>
<div class="btn-group btn-group-spaced form-group" role="group" aria-label="Actions">
<?= $this->Form->button(__('Submit'), ['class' => 'btn orange btn-default']) ?>
<?= $this->Form->button(__('Clear'), ['class' => 'btn orange hollow btn-default ucase','id' => 'show-prof','type' => 'reset']) ?>
</div>
The 'type' => "email" will add a type attribute with the value email to the input.
Read: CakePHP Form helper.
Also, you can visit http://www.formvalidator.net/ for more validations
I am answering for my own question.
One small change needs to be done.
That is, instead of Form->text use Form->email to validate the email before submitting the form.
Code is like:
<?= $this->Form->email("email", [
'required' => true,
'label' => false,
'id' => "email",]);
?>

Zend Framework 2 Skeleton Layout [duplicate]

This question already has an answer here:
globally change ZF2 form formatting
(1 answer)
Closed 7 years ago.
I am creating a form using Zend Framework 2 and the Skeleton Application.
I want my layout to replicate the default example:
As you can see above, the form inputs stretch to the width of the screen. The code to produce this is (using just the email address field as an example):
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" placeholder="Email" id="exampleInputEmail1" class="form-control">
</div>
I would like the same result to happen when I add my own form element using Zend Framework 2 (Skeleton application). But when I add an element:
$this->add(array(
'name' => 'campaign_code',
'type' => 'Text',
'options' => array(
'label' => 'Campaign Code',
),
'attributes' => array(
'class' => 'form-control',
)
));
The resulting HTML is:
<div class="form-group">
<label>
<span>Campaign Code</span>
<input class="form-control" type="text" name="campaign_code">
</label>
</div>
Resulting in:
Notice how the label tag is surrounding the span and input elements? I don't want that. I want the label tag to close itself as in the first html example.
The form view helpers are so smart while rendering the elements from your form.
Add an id attribute with respective element
$this->add(array(
'name' => 'campaign_code',
'type' => 'Text',
'options' => array(
'label' => 'Campaign Code',
),
'attributes' => array(
'class' => 'form-control',
'id' => 'your_id',
)
));

How to handle multiple forms in the same view?

I have a default form for my specific view.
Through an element I (dinamically) include another view (using view extension) in order to provide an upload form.
My problem is that the second form seems to submit the first one.
Default form
<div class="content-box-content">
<?php
echo $this->Form->create("WebSubject", array(
'inputDefaults' => array(
'error' => array(
'attributes' => array(
'wrap' => 'span',
'class' => 'input-notification error png_bg'
)
)
)
));
?>
<?=$this->Form->input('id', array('type' => 'hidden'))?>
<?=$this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire'))?>
<?=$this->Form->input('description', array('type' => 'textarea', 'label' => 'Descriere', 'id' => 'description'))?>
<?=$this->Form->input('description_long', array('type' => 'textarea', 'label' => 'Continut', 'id' => 'description_long'))?>
<?=$this->Form->submit('Salveaza', array('class' => "button"))?>
</div>
This way I include the element
<div class="tab-content default-tab" id="fotoUploadTab">
<?php
echo $this->element('file_upload_form', array(
'view' => 'upload_admin',
'webFileType' => 'image',
'redirect' => $SHT['here']
)
);
?>
<div class="tab-content default-tab">
Lista imagini
</div>
</div>
Element code
<?php
$view = (isset($view)) ? $view : "upload_admin";
$webFileType = (isset($webFileType)) ? $webFileType : "image";
$redirect = (isset($redirect)) ? $redirect : "/";
?>
<?php
$this->extend("/WebFiles/".$view);
?>
Extended View code
<div class="tab-content default-tab">
<?php echo $this->Form->create("WebFile", array('action' => '/', 'type' => 'file')); ?>
<input type="hidden" name="redirect" value="" />
<?php echo $this->Form->input('entity_id', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('entity_table_name', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('type', array('type' => 'hidden')); ?>
<?php echo $this->Form->input('title', array('class' => "text-input small-input", 'label' => 'Denumire')); ?>
<?php echo $this->Form->input('description', array('class' => "text-input small-input", 'label' => 'Descriere')); ?>
<?php echo $this->Form->submit('Upload', array('class' => 'button')); ?>
</div>
As seen in the last snippet, I tried to force the last form by providing an action url, but on submiting it, it sends data as the first one does.
How should I handle this ?
Thank you!
If you just want to have both forms, the one from parent and the other from the child view/element make sure you call $this->Form->end() in both templates and that you are not nesting a form inside the other. Probably, in your case, just by adding end() to both forms will solve your issue.
As a side note, you cannot have a parent view opening a Form with $this->Form->create() and inject fields into it using the child view, basically because you need create() to be called before any input is rendered and parent views are rendered after the child is executed.

How can I use zend form decorator to render errors inside my paragraph tag wrapping label and input

I would like to render the following markup:
<div class="row">
<p>
<label>Your Name</label>
<input type="text" class="text_field" name="name">
<ul class="errors">
<li>Waarde is vereist en kan niet leeg worden gelaten</li>
</ul>
</p>
</div>
This is my Zend form element + decorator:
$this->addElement('text', 'name', array(
'label' => 'Naam:',
'class' => 'text_field',
'required' => true,
'decorators' => array(
'ViewHelper',
'Label',
'Errors',
array(array('row' => 'HtmlTag'), array('tag' => 'p')),
array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
)));
But this always renders the ul list below the p tag and never inside. It also adds an additional p tag below the list.
<div class="row">
<p>
<label class="required" for="name">Naam:</label>
<input type="text" class="text_field" value="" id="name" name="name">
</p>
<ul class="errors">
<li>Waarde is vereist en kan niet leeg worden gelaten</li>
</ul>
<p></p>
</div>
What am I doing wrong?
Found it! My stupid mistake. I did only check the final rendered output in my browser. I am using a template which also loads javascript and this changes the DOM which creates the unwanted result.
So the first decorator setup was working correct.
Try to do the following:
$this->addElement('text', 'name', array(
'label' => 'Naam:',
'class' => 'text_field',
'required' => true,
'decorators' => array(
'ViewHelper',
'Label',
'Errors',
array(array('content' => 'HtmlTag'), array('tag' => 'p')),
array(array('content' => 'HtmlTag'), array('tag' => 'div', 'class' => 'row'))
)));