Welcome Guest, Not a member yet? Register   Sign In
Help in Form Helpers using Validation Class
#1

[eluser]Civic[/eluser]
Hi, I am a newbie in CodeIgniter. Can I place a validation in a form_input? Because in the examples in the forums, the view uses html tags while I used echo form_input($field_id).

Where model index is;
$data['field_id'] = array('field_id'=>'field_id','maxlength'=>8,'size'=>8);

Where controller index is;
$this->load->view('module1/add',$data);

Where add view is;
<?php
$attributes = array('name' => 'addView', 'id' => 'addView');
echo form_open('modules/add',$attributes);
?>
<?php echo form_input($field_id);?>

<?php echo form_close();?>

How do I add?
$rules['field_id'] = "required";
$this->validation->set_rules($rules);

Thanks in advance..
#2

[eluser]Civic[/eluser]
any guess anyone?
#3

[eluser]xwero[/eluser]
The common use is that you do the validation in your controller. it doesn't matter if you use static html or let the html generate for you, form_input, the result should be the same.
#4

[eluser]Civic[/eluser]
Thanks xwero for the reply. I did what you said. But I need more help. It seems I cant display my error message. below is the snippets of my code. Can you check what am I doing wrong? Thanks.

Where model index is;

$data['field_id'] = array('name'=>'field_id',
'maxlength'=>8,
'size'=>8,
'value'=>(isset($this->validation->field_id) ? $this->validation->field_id : '')
);
Where controller add is;
$rules['field_id'] = "required";
$this->validation->set_rules($rules);
if($this->input->post('save')){
if ($this->validation->run() == FALSE) {
$this->load->view('modules/addView',$data);
} else {
$this->modules_model->add();
$data['query'] = $this->modules_model->getall();
$this->load->view('modules/index',$data);
}
} else {
$this->load->view('modules/addView',$data);
}
Where add view is;

<?php
$attributes = array('name' => 'addView', 'id' => 'addView');
echo form_open('modules/add',$attributes);
?>
<?php echo form_input($field_id);?>
<?php echo $this->validation->field_id_error; ?>
<?php echo form_submit('save','Save');?>
<?php echo form_close();?>
#5

[eluser]Derek Allard[/eluser]
[moved to Application Development forum to get more eyeballs on it for you Civic]




Theme © iAndrew 2016 - Forum software by © MyBB