Welcome Guest, Not a member yet? Register   Sign In
form_validation and URI segment variable
#1

[eluser]joehopkins[/eluser]
HI,

I'm new to CodeIgnter and can't find any answers to this in the forum (I found one user with the same issue but the solution didn't match mine), so I'm assuming I'm taking the wrong approach.

Background

I have successfully used the form_validation class for my login. I liked it; so I want to keep using it.

I have a system where you edit a user, the URI being:

Code:
/users/edit/123

It's a simple pre-populated form using values from the DB, with the '123' being the user id.

The Problem

The form_validation tutorial in the CI user guide features a simple login form that loads the same view (passing no URI segment variable).

So when the form tries to validate it loads the 'users/edit' view without the user_id URI which throws all sorts of errors, as you can imagine. (It does not have the user_id to populate the form)

What I have tried

Well, I added some bletcherous code that detects the user_id from the post variables, should there not be the URI segment. This works, but does not load my form_error() strings. So, actually it doesn't really work.

In summary, from what I can fathom, either:

1) I'm doing it all wrong - my approach is fundamentally flawed
2) There's something simple I have missed and I will be really embarrassed
3) The form_validation class is but a simple class, and only used for basic input forms.
4) I am rubbish and haven't grasped the CI URI concept

Many thanks in advance,

Joe
#2

[eluser]joehopkins[/eluser]
I have sussed it!! I am an idiot.

In case anyone else has the same issue.

Make sure your post method points to the URL with the URI segment. Put your validation in the edit() function.

Sorry if I wasted anyone's time over this!




Theme © iAndrew 2016 - Forum software by © MyBB