CodeIgniter Forums
Server or Client side validation? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Server or Client side validation? (/thread-11980.html)

Pages: 1 2


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Mr Lazy[/eluser]
Hi,

I have a one field form using the CI validation class, and I must say it is neat. But I also have a page in my application with a large number of checkboxes on it that are dynamicaly displayed based upon data from the database.

My question is, if the validation fails on that page, how do I persist the data? I cannot define it in the controller before hand as I do not know what checkboxes will be on that page.

I am thinking of using client-side (jQuery) validation that can do the validation and there will be no screen refresh, so on screen data persistence will not become an issue.

I am interested to know what experienced CI/PHP folks think about this.

Thanks,
Lazy


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Yash[/eluser]
I use normal validation and not jquery.

You can try ...


Server or Client side validation? - El Forum - 10-01-2008

[eluser]xwero[/eluser]
javascript validations should always be backed up by server side validation for the obvious reason.

If you keep the checkboxes in a database you also have the relations between the checkboxes so you can do a check on the posted values and see if it aren't orphan values. But instead of a warning i would complete the the relations, this makes the user feel less stupid and it saves you the trouble coming up with relation warnings.


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Mr Lazy[/eluser]
Sorry, maybe I am being a little thick, if I don't know which (or how many) checkboxes there are on the page, how do I re-populate them after screen refresh?

Thanks,
Lazy


Server or Client side validation? - El Forum - 10-01-2008

[eluser]xwero[/eluser]
I created a simple function to do this
Code:
function form_checked($field)
{
    return (isset($_POST[$field]))?' checked="checked"':'';
}
But you can create custom form_checkbox function that does the same if you like to use the form helper to generate your form fields.


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Colin Williams[/eluser]
Why don't you know that, Mr Lazy? Is your app just too lazy to care?


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Mr Lazy[/eluser]
Thanks xwero, neat little function. I guess the CI validation vs jQuery decision I am trying to make is also to do with the error message. I guess both forms of validation will be able to display an error message?

Thanks,
Lazy


Server or Client side validation? - El Forum - 10-01-2008

[eluser]Phil Sturgeon[/eluser]
There is no choice sadly, you must have Server validation or your data will have as much integrity as a US politician.

If its one or the other, use CodeIgniter (server-side) validation. If you want it to look pretty, use jQuery validation as well as CodeIgniter.

Not much point having a pretty set of error messages if the user can just turn it off and break your site.

I prefer a mix something like:

Code:
[removed]
$(function() {
    $('p.hidden').slideDown();
});
[removed]

<? if ($this->validation->error_string): ?>
    <p class="error hidden">&lt;?=$this->validation->error_string;?&gt;</p>
</p>

Obviously this assumes error is a big red box and hidden is display:none;

Might not be as pretty but simplifies things and means I only have one set of rules to worry about.


Server or Client side validation? - El Forum - 10-01-2008

[eluser]miky4e[/eluser]
But, Server AND Client validation not?


Server or Client side validation? - El Forum - 10-01-2008

[eluser]gRoberts[/eluser]
I have both. All of my forms have server side validation and then I add client side as a feature. This means that if javascript is disabled, the validation still occurs on postback.