Hello everyone,

first of all I apologize for my English.

I have a problem with jquery.form plugin (http://jquery.malsup.com/form/).

I'm trying to make a form (who appears in a jqueryui modal dialog) to add a 
"Client" if it is not present in a select in another model add view. To do 
this I use this jquery function:

>
> $(function () {
>    var getModal = function () {
>         $('#clientForm').dialog({
>             modal: true,
>             autoOpen: false,
>             title: 'Aggiungi un cliente'
>         });
>  
>         $(".addclient").click(function() {
>             $('#clientForm').dialog('open');
>         })
>     };
>  
>     var showResponse = function (responseText) {
>       if (responseText == "Success") {
>               $('#clientForm').dialog('close');
>               window.location.reload();
>       }
>     };
>     
>     function showRequest(formData, jqForm, options) { 
>         // formData is an array; here we use $.param to convert it to a 
> string to display it 
>         // but the form plugin does this for you automatically when it 
> submits the data 
>         var queryString = $.param(formData); 
>      
>         // jqForm is a jQuery object encapsulating the form element.  To 
> access the 
>         // DOM element for the form do this: 
>         // var formElement = jqForm[0]; 
>      
>         alert('About to submit: \n\n' + queryString); 
>      
>         // here we could return false to prevent the form from being 
> submitted; 
>         // returning anything other than false will allow the form submit to 
> continue 
>         return true; 
>     } 
>  
>     $(document).ready(function() {
>       getModal();
>       
>         var submitOptions = {
>               beforeSubmit:  showRequest,  // pre-submit callback 
>               success: showResponse,
>               type: POST
>               //dataType: 'json'
>         };
>         $('#AddClientForm').ajaxForm(submitOptions);
>     });
> });
>
> The showRequest function is for debugging.

The problem is that the data inserted in the form are saved, but i get 
redirected to Client/index view instead of remaining in this page.

In addition the showRequest function is not executed (I don't see any 
alert).

The controller add function:

>
> public function add() {
>         if ($this->request->is('post')) {
>             $this->Client->create();
>             if ($this->Client->save($this->request->data)) {
>                 $this->Session->setFlash(__('The client has been saved'));
>                 $this->redirect(array('action' => 'index'));
>             } else {
>                 $this->Session->setFlash(__('The client could not be saved. 
> Please, try again.'));
>             }
>         }
>     }
>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to