Welcome Guest, Not a member yet? Register   Sign In
Form validation with redirect
#14

(This post was last modified: 10-28-2015, 02:49 AM by joseph.dicdican.)

(10-28-2015, 02:39 AM)msheath Wrote: Thanks for that. I have used your flashdata solution successfully. The only issue is that the flashdata variable is passed as a string and I want it to be an array so that I can show each error individually. Fortunately this is easily done using a separator parameter of '/n'. Of course I can't use the codeigniter function form_errors() but that isn't a problem. Although this works fine, it may still not be the best solution I suspect.

I am glad that helped you somehow. You're welcome. I agree to what you mentioned here,
Quote:Although this works fine, it may still not be the best solution I suspect.
For me, I still need to study about flashdata and whats the use of this in our codeigniter projects. 

For my side I commonly use this kind of codes below to implement error messages reporting/notifications,

Controller part,
PHP Code:

Code:
// intended for errors, titles etc.
private $data = array();

public function dummy() 
{
    $this->send();

    $this->load->view('test/test', $this->data);
}

private function send() 
{
    $this->data['hasError'] = true;
    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'trim|required');

    if($this->form_validation->run()) {
        $this->data['hasError'] = false;
        //do some stuff here
    }
View part,

Code:

Code:
<?php if($hasError) { // check if has error ?> 
   <section id="errors">
       <?php echo validation_errors(); ?>
   </section>
<?php } //close if has error ?>
We have different style and its up to us how we deal with it. Any style will do as long as their is a result but best practices really matters in the world of programming.  Big Grin

Thank you.

-joseph.dicdican  Big Grin
Joseph K. Dicdican
Softshore Global Solutions Inc. | Junior Web Developer Intern
Passerelles numériques Philippines | Scholar
[email protected] 
Reply


Messages In This Thread
Form validation with redirect - by msheath - 10-26-2015, 04:42 AM
RE: Form validation with redirect - by Martin7483 - 10-26-2015, 05:34 AM
RE: Form validation with redirect - by msheath - 10-26-2015, 07:26 AM
RE: Form validation with redirect - by Martin7483 - 10-26-2015, 07:44 AM
RE: Form validation with redirect - by msheath - 10-26-2015, 08:09 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:39 AM
RE: Form validation with redirect - by joseph.dicdican - 10-28-2015, 02:48 AM
RE: Form validation with redirect - by Narf - 10-27-2015, 03:42 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:54 AM
RE: Form validation with redirect - by Narf - 10-28-2015, 04:21 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 04:50 AM
RE: Form validation with redirect - by Martin7483 - 10-27-2015, 12:16 PM
RE: Form validation with redirect - by msheath - 10-28-2015, 02:15 AM
RE: Form validation with redirect - by mwhitney - 10-27-2015, 12:29 PM
RE: Form validation with redirect - by Martin7483 - 10-28-2015, 02:41 AM
RE: Form validation with redirect - by Martin7483 - 10-28-2015, 05:00 AM
RE: Form validation with redirect - by msheath - 10-28-2015, 05:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB