[eluser]maulik13[/eluser]
Hi,
I have been working with CI for some time now and I am wondering if I can separate form validation into a separate function. For example,
Code:
private function _ShowEditForm($formData){
$data = array();
$data = $data + $formData;
...
$data['submitlink'] = "downloads/validate";
$this->data["content_html"] = $this->load->view("download-add-view", $data, TRUE);
$this->_DisplayPage();
}
public function Validate(){
// validation
$data = array();
$data['dwn_name'] = $this->input->post('inDwnName');
$data['dwn_link'] = $this->input->post('inDwnLink');
$data['dwn_desc'] = $this->input->post('inDwnDesc');
$this->form_validation->set_rules("inDwnName", "User Email", "trim|required");
if($this->form_validation->run())
{
// success //
// add data or check custom validation //
}
else{
$this->ShowForm($data);
}
}
However, with this code set_value('') does not work in my form. It works if I keep the validation in the same function which displays the form (like in user guide example).
Can anyone give me an idea of what could I do to separate validation in a function and make set_value work or what kind of other
approach I can take to re-populate the forms?
Thanks.