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)
- 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;')) ;
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
- 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'
- )
- );
- ?>
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
- 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;
- }
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
Possibly related Questions
-
Ajax Cform validation within renderPartial view
February 7, 2012 By TheDeveloper 4 Answers
-
CJuiDialog: referencing attribute
January 23, 2012 By msimaremare 2 Answers
TAGS
actioncreate ( x 2 )ACTIVERECORD ( x 4 )AJAX ( x 10 )ajaxSubmitButton ( x 4 )AR ( x 2 )cactivedataprovider ( x 2 )CActiveForm ( x 2 )cactiverecord ( x 2 )CGridView ( x 14 )CJuiAutoComplete ( x 3 )CJuiDialog ( x 8 )CListView ( x 8 )controller ( x 7 )Css ( x 2 )CStarRating ( x 2 )CTreeView ( x 2 )database ( x 5 )dialog ( x 2 )dropdownlist ( x 3 )EGMaps ( x 3 )extension ( x 3 )file ( x 2 )form ( x 6 )Giix ( x 2 )gridview ( x 2 )html ( x 2 )javascript ( x 3 )many_many ( x 4 )merge ( x 2 )model ( x 4 )Modules ( x 3 )multilanguage ( x 2 )php ( x 2 )redirect ( x 4 )Registration ( x 3 )relations ( x 5 )renderPartial ( x 8 )session ( x 2 )sorting ( x 3 )sql ( x 4 )url ( x 3 )urlManager ( x 3 )validation ( x 3 )yii ( x 11 )YiiAnswers Site ( x 4 )This website counts Questions and 429 Answers by 7522 registered users.

I have a sort of answer …
Forget about putting the messages in the controller ….
Instead do it in the view.
'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
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
// 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
// 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