Form validation |
[eluser]loopyno[/eluser]
Hi guys, I really need your help because I am going crazy. I created a simple form on my site and I wanted to use the validation class. The only problem is that although - I think - I did all that is necessary to make it work I do not get an error message - neither for the form fields nor from the code I wrote ( so I understand that the code is correct ) What I realized is that $this->validation->error_messages does not get populated although I set the rules ( basic ones ) and the fields. The Controller code is below and you can se it not working here www.fuzzy-4x.com/contact. Any kind of help is really valued class Contact extends Controller { function Contact() { parent::Controller(); } function index() { $this->output->cache(0); $query = $this->db->query('SELECT text_name, text_value FROM texts where language = "'.$this->config->item('lang_selected').'"'); $temp = $query->result(); for($i=0; $i<count($temp); $i++) { $data[$temp[$i]->text_name] = $temp[$i]->text_value; } if(strlen($this->session->userdata('autohide')) < 1) { $this->session->set_userdata('autohide', 1); } $data['stop'] = $this->session->userdata('autohide'); $menu = array("home", "progress", "favorites", "about_me", "contact", "faq", "site_map"); if( !(in_array(trim($this->uri->segment(1)), $menu)) ) { if(strlen($this->session->userdata('current_page')) < 1) { $view = "home"; } else { $view = $this->session->userdata('current_page'); } } else { $view = trim($this->uri->segment(1)); } $rules['name'] = "required"; $rules['email'] = "required"; $rules['topic'] = "required"; $rules['message'] = "required"; $this->validation->set_rules($rules); $fields['name'] = 'contact_name'; $fields['email'] = 'contact_email'; $fields['topic'] = 'contact_topic'; $fields['message'] = 'contact_message'; $this->validation->set_fields($fields); $this->session->set_userdata('current_page', $view); $this->load->view('menu_view',$data); if ($this->validation->run() == FALSE) { $this->load->view('contact_view'); } else { $this->load->view('contact_success_view'); } $this->load->view('footer_view'); } }
[eluser]wiredesignz[/eluser]
Welcome to the forums, try using the forum tags [ code ] around your code [ /code ] Your controller looks basically ok, could you also post the view which displays the form and messages.
[eluser]loopyno[/eluser]
Sorry for not using code that was my first post Ok the view code is bellow: Code: <?$attributes = array('id' => 'contact_form');echo form_open('../contact', $attributes);?>
[eluser]garymardell[/eluser]
Code: <div class="left_text"> I have placed a error in bold. You have failed to start the php tags.And i don't see the purpose of it. It doesn't it in with the html which is another error. *added returns in your code for my benefit to read it. You have the same error on the next line as well.
[eluser]loopyno[/eluser]
well I do have a start tag for the php code. I do not understand why It was removed when I pasted the code here Here is a link to the code in txt format: www.fuzzy-4x.com/test.txt
[eluser]wiredesignz[/eluser]
Unless you have some pre-defined error message fields then you only have one choice to display validation errors. Code: $this->validation->error_messages;
[eluser]loopyno[/eluser]
than how come this works??? There is no setting for the error messages like in my script. Here is the link www.fuzzy-4x.com/form Controller: Code: <?php View Code: <?php echo form_open('form'); ?>
[eluser]wiredesignz[/eluser]
I apologise, you are correct, there are custom messages for each field (a new feature I wasn't aware of).
[eluser]loopyno[/eluser]
np One thing I saw in my code is that although I enter the correct data $this->validation->run() returns always FALSE maybe this could be a clue
|
Welcome Guest, Not a member yet? Register Sign In |