Welcome Guest, Not a member yet? Register   Sign In
Multidimensional Flashdata arrays?
#1

[eluser]sacarias[/eluser]
Do multidimensional arrays work with the flash data functions?

I have this code that works in normal php applications. i dont like to redirect to a success page so when there is an error on a form i like to use this to collect each error and display it to them right above the form.

Everytime you catch an error you use this

EX.
Code:
if(empty($username)){
$this->simpleMessages->addMessage("login-form", "error", "You must specify a username.");
}

Code:
function addMessage($location, $type, $description){
        return $this->messages[] = array("location" => $location, "type" => $type, "description" => $description));
    }

In order for the messages to be saved, they need to be saved in flashdata....which was the easiest fix, but now its turning out to be difficult.

thanks for your time.
#2

[eluser]bobbob[/eluser]
Looks like you are writing your own form validation when there is a great form validation library which repopulates the form fields with the submitted data and the relevant error message. Maybe I misunderstood something.
#3

[eluser]sacarias[/eluser]
Well, say if i want to sign up to a website. With the current form validation class - on success, you would have to make a success page. I dont want to do that.
I would like to have the user stay on the same page that they signed up on and they would see a success message. EX.(Thanks for signing up, please check your email to validate your account before you log in.);
#4

[eluser]bobbob[/eluser]
So you need AJAX.
Just submit to a controller that returns the errors or the success method and load it to the same div.
#5

[eluser]sacarias[/eluser]
I dont need ajax, because i need this to work normal if the client doesnt have javascript enabled.

Anyways, i just need to know if set_flashdata() can accept a multi dimensional array, and get stuff added to the same array key.
#6

[eluser]gvillavizar[/eluser]
[quote author="sacarias" date="1270875279"]I dont need ajax, because i need this to work normal if the client doesnt have javascript enabled.

Anyways, i just need to know if set_flashdata() can accept a multi dimensional array, and get stuff added to the same array key.[/quote]

To answer your question: no, flashdata can't hold multidimensional array.

And about your problem, you don't need ajax, and you don't need a success page either. Using the form validation class we can load the form view if the submission wasn't successful. If the submission was successful just clear up the form data, set a flashdata variable and then load the signup form again with the flashdata displaying.

Its actually a simple issue that may turn into a monster if you want to handle it all by yourself.

If you need a little more deep explanation just let me know.
#7

[eluser]sacarias[/eluser]
Thank you for answering my question grad student.
I actually cannot believe i didnt think of that solution, it must be because im new to codeigniter/mvc frameworks.

thanks a lot! Smile




Theme © iAndrew 2016 - Forum software by © MyBB