Welcome Guest, Not a member yet? Register   Sign In
Yet another yet another validation question
#1

[eluser]Unknown[/eluser]
Hi All,

I'm having some issues with the Validation class. It works correctly within one controller, but then when I pass to another controller, the same code does nothing, i.e., the run() method is returning true. I'm a newbie to CI, and not much better on PHP (I do mostly java).

Here's my index function in one controller:

Code:
$this->load->helper('html');
        $this->load->library('validation');

        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        $rules['abstractTitle'] = "required";
        $rules['abstractText'] = "required";

        $this->validation->set_rules($rules);

        $fields['abstractTitle']    = 'Abstract Title';
        $fields['abstractText']    = 'Abstract Text';

        $this->validation->set_fields($fields);

        if ($this->validation->run() == FALSE)
        {

            $this->load->view('abstract/abstract_form_view');
        }
        else
        {
            $this->add();
        }

My abstract_form_view.php (partial)

Code:
<div>
    <label>Abstract Title: </label>
    &lt;?=$this->validation->abstractTitle_error; ?&gt;
    &lt;input type="text" name="abstractTitle" id="abstractTitle"
        value="&lt;?=$this-&gt;validation->abstractTitle; ?&gt;" maxlength="50" size="50" />
</div>
&lt;?php echo br(2); ?&gt;
<div>
    <label>Abstract Text:  </label>
    <p>(Paste or type in your abstract here - please, no more than 250 words.)</p>
    &lt;?=$this->validation->abstractText_error; ?&gt;
    &lt;textarea name="abstractText" id="abstractText"
        rows="25" cols="80" &gt;&lt;?php echo $this->validation->abstractText;?&gt;&lt;/textarea&gt;
</div>

When abstractText or abstractTitle are blank, the run() passes, and I get to the add().

I have the same code in another controller, and the validation works fine. I'm sure I'm missing something simple. I've read a few other related posts, and except for the multiple pages validation issue, they don't seem to be relevant. If the multiple pages issue is relevant, I'd appreciate any hints.

thanx
steve
#2

[eluser]Unknown[/eluser]
NEVER MIND!!! ;-0

I found my stupid mistake. I was routing the form to the add() function rather than back to the index() function.

Thanks for listening, though. ;-)

steve




Theme © iAndrew 2016 - Forum software by © MyBB