Welcome Guest, Not a member yet? Register   Sign In
help with form validation and uri segments
#1

[eluser]Flying Fish[/eluser]
I'm building a form that user's input information that they want on different promo items like postcards, flyers etc.

Right now I have it set up so that there is one method in my order controller 'order/add_info'

This loads a view that will display the order form

I was going to have the view check the URI and display different form fields based on what URI segments were there

controller 'order' method 'add_info' argument 1 type of item 'flyer' argument 2 design 'classic'

for example
'order/add_info/flyer/classic'
would display a form with say 10 fields

but
'order/add_info/postcard/summer_fun'
would display a form with 4 fields

I have validation rules set up in a config file for 'order/add_info'

when I submit a form from the url 'order/add_info' all the validation works great

but if I submit a form from any url with segments like 'order/add_info/flyer/classic' the validation errors do not show up

is there a way to get form validation to work even with different uri segments? I really want to use the same validation rules for each item since the field names are all the same, it's just some items don't have as many fields as others

or am I just going about things the wrong way?

I'll attach the view file to this post any help would be appreciated. Thanks!
#2

[eluser]xwero[/eluser]
I think instead of adding the rules to the config file you better put the rules in the add_info method.
Code:
$this->load->library('form_validation')

// rules for fields that are present on every form for example the 4 postcard summer fun fields

// rules for fields that are present on specific forms
switch($this->uri->segment(3))
{
   case 'flyer':
       // the six other fields
       break;
}

// validate
#3

[eluser]Flying Fish[/eluser]
I'll give that a shot and see how it goes. Thanks!
#4

[eluser]Flying Fish[/eluser]
I was able to get it working by calling the specific rule group as shown here

[code]
$this->form_validation->run('order/add_info')
[code]

That way I can leave the rules in the form_validation file in the config folder

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB