Author Topic: CakePHP Jquery Ajax problem  (Read 1709 times)

0 Members and 1 Guest are viewing this topic.

Offline soma80Topic starter

  • Irregular
  • Posts: 1
    • View Profile
CakePHP Jquery Ajax problem
« on: March 06, 2009, 03:42:33 PM »
Veiw File .. forms.ctp

Code: [Select]
<?php
echo $javascript->link('jquery',false);

echo 
$form->create('User', array('default' => false));
?>
 
<div class='form2'>
 
<div class='lable2'> <?php echo $form->label('Enter Email'); ?> </div>
<?php
echo $form->text('email',array('class' => 'input'));  
?>

<p> 
<?php
echo $form->submit('Send',array('class' => 'but2',
'onclick'=>'              
         $.post("/Users/forms",{email:"admin@localhost"}, function(data){
              alert('
OK');              
   });              
     
          '
));
echo 
$form->submit('Cancel',array('class' => 'cancel','onclick'=>'self.parent.tb_remove()'));
?>

</p> 
<div id="#message"> <div/>
</div>
<?php
echo $form->end();
?>


Controller File

Code: [Select]
<?php
class UsersController extends Appcontroller{
 var 
$name='Users';
 var 
$helpers = array('Form','Javascript','Html','Ajax');  
 var 
$components = array('Cookie','Email','RequestHandler');    
 
function 
forms() {  
  
$this->pageTitle 'Home';  
  
$this->layout 'space'
  if (!empty(
$this->data)) {           
   
    if(
$this->RequestHandler) {         
     if((
$user $this->User->validateEmail($this->data['User'])) == true) {   
      
$this-> __sendNewUserMail();     
      
$this->set('data','ok');   
     }

     else {       
      
$this->Session->setFlash('&#1593;&#1601;&#1608;&#1575;&#1611;.. &#1575;&#1604;&#1605;&#1593;&#1604;&#1608;&#1605;&#1575;&#1578; &#1575;&#1604;&#1578;&#1610; &#1575;&#1583;&#1582;&#1604;&#1578; &#1594;&#1610;&#1585; &#1589;&#1581;&#1610;&#1581;&#1577; .','fail_message');  
 } 
    }

   }   
   if (empty(
$this->data)) {
    
$this->User->create();
   }    
  } 

function 
__sendNewUserMail() { 
   
/* SMTP Options */
   
$this->Email->smtpOptions = array(
    
'port'=>'25'
    
'timeout'=>'30',
    
'host' => 'localhost',
   );

   
/* Set delivery method */
   
$this->Email->delivery 'smtp';

   
/* Do not pass any args to send() */
   
$this->Email->to =$this -> data['User']['email'];
   
$this->Email->subject 'Welcome to our really cool thing';    
   
$this->Email->from 'Cool Web App <app@example.com>';
   
$this->Email->send('Hello');

   
/* Check for SMTP errors. */
   
$this->set('smtp-errors'$this->Email->smtpError);  
}
}
?>


Th problem is The ajax not work when click submit button , but if I change ajax part by any thing like alert('???? '); the code excute ..

 :-[