CodeIgniter Forums
Help in Form Helpers using Validation Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Help in Form Helpers using Validation Class (/thread-9865.html)



Help in Form Helpers using Validation Class - El Forum - 07-10-2008

[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..


Help in Form Helpers using Validation Class - El Forum - 07-11-2008

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


Help in Form Helpers using Validation Class - El Forum - 07-11-2008

[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.


Help in Form Helpers using Validation Class - El Forum - 07-11-2008

[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();?>


Help in Form Helpers using Validation Class - El Forum - 07-11-2008

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