Welcome Guest, Not a member yet? Register   Sign In
Form_validation unset 'set_rules'
#1

[eluser]Walle[/eluser]
Hello,

I have a view with two blocks. A and B. Both are used to write/change data on the database. Both blocks are in one <form> tag on the view. Now the thing I wan't to achieve is, that when I press the submit button, block B will be checked with some validation rules, and if they all succeed, block B should be comitted to the database.

After block B gets validated, block A should be validated and committed to the database as well. That is not hard to achieve.

But if B fails, I still want to validate A to be committed to the database, and they have to be in that order. First B, then A. You might say that A always has to be validated.

I have not really an idea how to achieve that. I wrote something like this in my controller:

Code:
// block B
$this->form_validation->set_rules('description', 'Description', 'required');
if ($this->form_validation->run() == TRUE) {
    // execute code for block B

    // validation for block A
    $this->form_validation->set_rules('responsible_user', 'Responsible_user', '');
    if ($this->form_validation->run() == TRUE) {
        // execute code for block A
    }
} else {
// block A
    ???
    $this->form_validation->set_rules('responsible_user', 'Responsible_user', '');
}

I have to remove the first rule I specified in block B where I put the question marks in the else clause. But I don't have an idea how to do that.

Anyone has any ideas?

It would really help me out.

Kind regards,

Walle
#2

[eluser]Walle[/eluser]
I managed to fix it, in this way:

I removed the required check on the field 'description' and later in my code, I checked if the length of the submitted value was larger than 0.

Not an answer to my question, but at least my form works now.
#3

[eluser]rufnex[/eluser]
Why not just validate B then A in every case?

Code:
// block B
$this->form_validation->set_rules('description', 'Description', 'required');
if ($this->form_validation->run() == TRUE) {
    // execute code for block B
}
// validation for block A
$this->form_validation->set_rules('responsible_user', 'Responsible_user', '');
if ($this->form_validation->run() == TRUE) {
    // execute code for block A
}






Theme © iAndrew 2016 - Forum software by © MyBB