Welcome Guest, Not a member yet? Register   Sign In
Extended form_validation: now with file checking :)
#41

[eluser]alboyd[/eluser]
Yeh I noticed that. The problem is - without checking for count($_POST) > 0 before setting the validation rules, they are fired all the time. I noticed my other forms with nothing to do with FILES were displaying the errors even though the page had only just been loaded.

Will there be a way to fix this or will I have to add that code to all my forms? I've got LOTS!
#42

[eluser]alboyd[/eluser]
Any reason you can't change your code to this:
Code:
if(count($_POST)===0 && count($_FILES) > 0)//it will prevent the form_validation from working
        {
            
            //add a dummy $_POST
            $_POST['DUMMY_ITEM'] = '';
            parent::set_rules($field,$label,$rules);
            unset($_POST['DUMMY_ITEM']);
        }

And the same for the "run" function.

It seems to work for me so far I haven't found a problem with this?
#43

[eluser]devbro[/eluser]
[quote author="alboyd" date="1251432536"]Any reason you can't change your code to this:
Code:
if(count($_POST)===0 && count($_FILES) > 0)//it will prevent the form_validation from working
        {
            
            //add a dummy $_POST
            $_POST['DUMMY_ITEM'] = '';
            parent::set_rules($field,$label,$rules);
            unset($_POST['DUMMY_ITEM']);
        }

And the same for the "run" function.

It seems to work for me so far I haven't found a problem with this?[/quote]

I just incorporated that change into my code. Wink it is now version 2.1
#44

[eluser]echoDreamz[/eluser]
Does this work with, or replace the existing form validation library?
#45

[eluser]devbro[/eluser]
[quote author="echoDreamz" date="1252318792"]Does this work with, or replace the existing form validation library?[/quote]

It extends, basically adds functionality to CURRENT form_validation library.
#46

[eluser]dallen33[/eluser]
Any reason why an error message isn't being displayed when no file is selected?

CONTROLLER
Code:
$this->form_validation->set_rules('userfile','Image','file_required');
VIEW
Code:
<p class="input_text">
<label for="userfile">Select Photo</label>
&lt;input type="file" name="userfile" id="userfile" /&gt;
&lt;?php if (form_error('userfile')): echo '<span class="error">'.form_error('userfile').'</span>'; endif; ?&gt;
</p>
#47

[eluser]devbro[/eluser]
[quote author="GodsHand" date="1255573721"]Any reason why an error message isn't being displayed when no file is selected?

CONTROLLER
Code:
$this->form_validation->set_rules('userfile','Image','file_required');
VIEW
Code:
<p class="input_text">
<label for="userfile">Select Photo</label>
&lt;input type="file" name="userfile" id="userfile" /&gt;
&lt;?php if (form_error('userfile')): echo '<span class="error">'.form_error('userfile').'</span>'; endif; ?&gt;
</p>
[/quote]

How are you opening your form? multipart?
#48

[eluser]dallen33[/eluser]
I'm using multipart. Also, when I use:

Code:
&lt;?php echo validation_errors(); ?&gt;

I get the error, but using the way I mentioned above brings no error. Weirdness...
#49

[eluser]devbro[/eluser]
Thanks for letting me know. I will try to figure out why it happens and let you know.
#50

[eluser]dallen33[/eluser]
Thanks, dude! This is an awesome extension btw. Thank you Smile




Theme © iAndrew 2016 - Forum software by © MyBB