Register here!

Forgot password?

ASK NEW QUESTION

Home Page » Zii » Jui » ajaxSubmitButton w/ Yii::app()->user->hasFlash
0 Votes
Vote Con!
Solved!

ajaxSubmitButton w/ Yii::app()->user->hasFlash

ajaxSubmitButtonCJuiDialogsetFlash

Hello all,

I have a problem showing a message though Ajax.

Here is the main idea (& some code)
I have a link that when clicked opens a CJuiDialog which asks your email address using CActiveForm.
After you type in the email address & click the “Send To Friend” ajax submit button, an email is sent & the dialog is closed.
What I want now is to show a message in the main windows (not modal dialog) of success or error.
I know the theory. Update the background layer in Javascript (on success). But I can’t get it to work. Any links or code would be appreciated.

Main Windows (view)

  1.                  
  2.                     user->hasFlash('success')):?>
  3.                        
  4.                         user->getFlash('success'); ?>
  5.                        
  6.                    
  7.                     user->hasFlash('error')):?>
  8.                        
  9.                         user->getFlash('error'); ?>
  10.                        
  11.                    
  12.  
  13.  
  14. ....
  15.  
  16. echo CHtml::link(utf8_encode('Send to a friend'), '#', array( 'onclick'=>'$("#enviarAmigoDialog").dialog("open"); return false;')) ;
				  
					user->hasFlash('success')):?>
					    
						user->getFlash('success'); ?>
					    
					
					user->hasFlash('error')):?>
					    
						user->getFlash('error'); ?>
					    
					


....

echo CHtml::link(utf8_encode('Send to a friend'), '#', array( 'onclick'=>'$("#enviarAmigoDialog").dialog("open"); return false;')) ;

In the cjuiDialog/form

  1.      
  2.         labelEx($correoAmigo,'email',  array('class'=>'textLabel'));  ?>
  3.         textField($correoAmigo,'email',array( 'class'=>'textField')); ?>
  4.         error($correoAmigo,'email'); ?>
  5.    
  6.  
  7.    
  8.        
  9.         $enviarAmigoID , 'render'=>true)),
  10.                 array(  'update' => '#data',
  11.                
  12.                     'success'=>'js: function(data) {
  13.                         $("#enviarAmigoDialog").dialog("close");
  14. // Don't know what goes here *********                 
  15.                     }'
  16.                    
  17.                 )
  18.                         ,array( 'id'=>'closeAmigoDialog',
  19.                             'class'=>'cta_button agregar'
  20.                         )
  21.                         );
  22.                    
  23.         ?>
  24.    
      
        labelEx($correoAmigo,'email',  array('class'=>'textLabel'));  ?>
        textField($correoAmigo,'email',array( 'class'=>'textField')); ?>
        error($correoAmigo,'email'); ?>
    
 
    
       
        $enviarAmigoID , 'render'=>true)),
				array(	'update' => '#data', 
				
					'success'=>'js: function(data) {
						$("#enviarAmigoDialog").dialog("close"); 
// Don't know what goes here *********				 	
					}'
					
				)
                    	,array(	'id'=>'closeAmigoDialog',
                    		'class'=>'cta_button agregar'
                    	)
                    	); 
        			
         ?>
    

In the controller (amigo/enviarAmigo) after the sendmail action is performed I have

  1. if($correoAmigo->validate())
  2.             {
  3.                 ...
  4.  
  5.  
  6.                 Yii::app()->user->setFlash('success','Thank you for contacting us. We will respond to you as soon as possible.');
  7.                 Yii::app()->clientScript->scriptMap['jquery.js'] = false;
  8.            
  9. }
if($correoAmigo->validate())
			{
				...


				Yii::app()->user->setFlash('success','Thank you for contacting us. We will respond to you as soon as possible.');
				Yii::app()->clientScript->scriptMap['jquery.js'] = false; 
			
}

How do I display a flash message from an action in a CJuiDialog in a background page w/o refreshing.

Thanks

By tuolden in Jui · Asked 595 days 12 hours ago

Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0

 

Answers (2)

  1. 0 votes

    I have a sort of answer …

    Forget about putting the messages in the controller ….
    Instead do it in the view.

    1.                     'success'=>'js: function(data) {
    2.                        
    3.                         $("#mensajes_error").html("Mensaje enviado con exito");
    4.                         $("#enviarAmigoDialog").dialog("close");
    5.                    
    6.                     }'
    					'success'=>'js: function(data) {
    						
    						$("#mensajes_error").html("Mensaje enviado con exito");
    						$("#enviarAmigoDialog").dialog("close"); 
    				 	
    					}'

    Any other ideas?

    By tuolden · 595 days 10 hours 50 mins ago

    Questions: 25 Accepted: 0 ( 0% ) | Reputation: 0

  2. 1 vote
    Accepted

    Hi tuolden,

    When you do an AJAX call, the normal procedure is to ‘echo’ a result to the calling function. In your success, there is nothing like that…

    On Controller

    1. // on controller
    2. if($correoAmigo->validate())
    3. {
    4.         echo 'Thank you for contacting us. We will respond to you as soon as possible.';
    5. }else
    6.        echo 'Error';
    // on controller
    if($correoAmigo->validate())
    {
            echo 'Thank you for contacting us. We will respond to you as soon as possible.';
    }else
           echo 'Error';

    On success

    1. // on success
    2. 'success'=>'js: function(data) {
    3.  // this is too simple, consider using JSON to
    4.  // check response statuses (error, success) whatever
    5.  $("#mensajes_error").html(data);
    6.  $("#enviarAmigoDialog").dialog("close");
    7. }'
    // on success
    'success'=>'js: function(data) {
      // this is too simple, consider using JSON to
      // check response statuses (error, success) whatever
      $("#mensajes_error").html(data);
      $("#enviarAmigoDialog").dialog("close");
    }'

    By tonydspaniard · 594 days 19 hours 38 mins ago

    Questions: 2 Accepted: 0 ( 0% ) | Reputation: 0

© YiiAnswers.com 2011. All rights reserved.

Switch to our mobile site