Welcome Guest, Not a member yet? Register   Sign In
Form validation and Drop down list
#1

[eluser]foysal[/eluser]
Hi all

which can I use for form validation?? first one or second one?

Code:
if ($this->form_validation->run() == FALSE)

  {
              
    redirect('login/events');
              
   }
          
   else
   {
      ..............................
    }

or

Code:
if ($this->form_validation->run() == FALSE)

  {
              
    $this->load->view('events');
              
   }
          
   else
   {
      ..............................
    }



I am using drop down list by using CI form_dropdown('');


how can I set the first value of drop down list?? like "Select Month" or "Select a value" or "Select an Item" which instruct me to select a value.


Foysal
#2

[eluser]danmontgomery[/eluser]
If you redirect on failed form_validation, you'll lose any error messages generated by the validation. You should only redirect after a successful validation and done whatever you want to do with the validated data.

form_dropdown() generates a select field from whatever you give it. So the first option is the first option in the array.

Code:
echo form_dropdown('my_field', array('' => 'Select Month', 1 => 'January', 2 => 'February', etc));
#3

[eluser]foysal[/eluser]
Dear nocturm

you wrote "If you redirect on failed form_validation, you’ll lose any error messages generated by the validation."


why i am loosing error message?? what can i do here??


i am pushing a view inside another view, thats why i am using redirect () to reach the controller and function. what can i do in this situation??



thanks for reply

Foysal
#4

[eluser]danmontgomery[/eluser]
You lose error messages because they aren't persistent across page views. In order to keep them you'd have to save them to the session (flashdata, most likely) before redirect, which is all a bit of a hassle.

What you should be doing if form validation fails is re-displaying the form, with the validation errors. There's a pretty thorough explanation of this in the user guide.




Theme © iAndrew 2016 - Forum software by © MyBB