Welcome Guest, Not a member yet? Register   Sign In
Show name “corrupted” when validation fails

I'm having this name field
PHP Code:
<?php echo form_label('Your Name <span class="required">*</span>''name', array('class' => 'col-sm-3 control-label')); ?>
                            <div class="col-sm-9">
                                <?php echo form_input('name'set_value('name'$this->input->post('name')), 'class="form-control"'); ?>
                                <?php echo form_error('name'); ?>

and these are the validation rules

PHP Code:
$config = array(
'name' => array(
'field' => 'name',
'label' => 'Name',
'rules' => 'required|trim|min_length[2]',

I've spotted an issue when trying to validate the field. If I type a name like Mc'Donalds and hot submit I get this from set_value()


How can I fix this issue ?

I 've tried using htmlscecialcars_decode() and html_entity_decode() with ENT_QUOTES or ENT_COMPAT, but didn't do the trick

I am not sure I understand the problem as the example you have given looks right.

However, set_value works like this:

You have
PHP Code:
set_value('name'$this->input->post('name'))   // **** Not correct use of second term 

When it should be just

PHP Code:
set_value('name''Your name'); 

The second term on the set_value should be your default, or nothing was submitted value, not the input post value. That is done with the first term, in your case 'name', so it looks for any post value with that post name and uses that, or if not found, uses the default term, the second term.

You can see it explained much better here: http://www.codeigniter.com/userguide3/he...#set_value

Hope that helps,


“corrupted” because the value was escaped. Set 3rd variable on set_value() to false. set_value('name','Your name',FALSE);
Keep calm.

Theme © iAndrew 2016 - Forum software by © MyBB