Welcome Guest, Not a member yet? Register   Sign In
set_value empty
#1

[eluser]Sean Delaney[/eluser]
Here is my view add.php file that contains a form:

Code:
<?php
$form_attributes = array('class' => 'add','id' => 'add');

$author_attributes = array(
'name' => 'author',
'id' => 'author',
'value' => '',
'placeholder' => 'Joe Bloggs',
'title' => 'Author'
);

$author_email_attributes = array(
'name' => 'author_email',
'id' => 'author_email',
'value' => '',
'placeholder' => '[email protected]',
'title' => 'Author Email'
);

echo form_open('add',$form_attributes);
echo form_label('Name:','author');
echo form_input($author_attributes,set_value('author'));
echo form_label('Email:','author_email');
echo form_input($author_email_attributes,set_value('author_email'));
echo form_submit('add','Submit');
echo form_close();
?>

In my controller I have set:

Code:
$this->load->library(array('form_validation'));
$this->load->helper(array('form','security'));
  
$this->form_validation->set_rules('author','Name','required|trim|xss_clean');
$this->form_validation->set_rules('author_email','Email','required|valid_email|trim|xss_clean');
$this->form_validation->set_error_delimiters('<li>','</li>');

If there is a field not filled in after I submit the form, the get the error messages but set_value is empty?

Any reason?
#2

[eluser]Nisha S.[/eluser]
I think when you pass a array as the first parameter the form_input() method will not use the second parameter. Just set the value in the array itself.
Code:
$author_email_attributes = array(
'name' => 'author_email',
'id' => 'author_email',
'value' => set_value('author_email'),
'placeholder' => '[email protected]',
'title' => 'Author Email'
);
#3

[eluser]Sean Delaney[/eluser]
Thanks. That worked perfectly!




Theme © iAndrew 2016 - Forum software by © MyBB