There is no point in validating via AJAX unless something related to
sessions needs to be checked. You should validate twice, once client-
side in javascript and again on the server. The jQuery Validation
plugin should cover your needs for this: 
http://docs.jquery.com/Plugins/Validation

On Aug 4, 10:02 pm, rem <remus.bo...@gmail.com> wrote:
> I've done some digging around and this doesn't seem to be a very good
> practice after all...
> I'm looking further for the best output but would appreciate your
> ideas as well.
> Thank you.
>
> On Aug 4, 10:58 pm, rem <remus.bo...@gmail.com> wrote:
>
> > Hello friends,
>
> > I am trying to validate a form using jQuery and PHP. The actual
> > filtering is done by a PHP class which receives the data
> > asynchronously from jQuery and if it finds the form field data
> > invalid, returns an error.
>
> > So, I am serializing the form and then split it into array. I'm
> > looping through the array and passing each value to the jQuery.ajax
> > function. I would need to return an error to the ID hook if something
> > is wrong and I'm stuck in creating it. PHP successfully returns the
> > information but I'm having a very hard time with the darn hook. Please
> > see the code below:
>
> > $(document).ready(function() {
> >     $(function() {
> >         $("#form-submit").click(function() {
> >             /*
> >             serialize the form and create the initial array
> >             */
> >             array = $("#theform").serialize().split("&");
> >             for(var i in array) {
> >                 /*
> >                 for each value, split it again and grab the element
> > key
> >                 which will be my CUSTOM_PARAMETER
> >                 */
> >                 arr = array[i].split("=");
> >                 var custom_parameter = arr[0];
> >                 /*
> >                 arr[0] is the key which is basically the
> > CUSTOM_PARAMETER I need
> >                 arr[1] is the actual value and makes no interest
> >                 */
> >                 $.ajax({
> >                       url: 'request.php',
> >                       type: 'POST',
> >                       data: array[i],
> >                       success: function(data) {
> >                           /*
> >                            PHP returns an error if the data is invalid
> >                            but I need to define a "hook" using the
> > CUSTOM_PARAMETER element
> >                            ex: $("#error_phone_number").html(data);
> >                           */
> >                           $("#error_"+custom_parameter).html(data);
> >                       }
> >                 });
> >             }
> >         });
> >     });
>
> > });
>
> > I hope I succeeded to make myself as clear as possible and of course,
> > I would really appreciate your thoughts on this.
>
> > Thank you!

Reply via email to