By press a button I send an email with sc_mail_send.
How can I show a message to the user while processing sc_mail_send ?
echo "Just a moment ... email sending ...";
...
...
sc_mail_send(...);
This appears the message AFTER the mail was send
By press a button I send an email with sc_mail_send.
How can I show a message to the user while processing sc_mail_send ?
echo "Just a moment ... email sending ...";
...
...
sc_mail_send(...);
This appears the message AFTER the mail was send
check the sc_ajax_message macro.
Regards
thank you kafecadm for your answer
If I use sc_ajax_message, nothing happens / shows. Does the macro not only run , when it is in an Ajax call ?
I call the mail macro in a button click Event âŚ
thanks
Hamu
You added a button and in the code field you add the sc_mail_send? This executes when you click the button, but itâs not an ajax call, itâs a regular server call, so you see the message as a response of the server after the code has been executed.
I think of two options:
First:
With jQuery you could intercept the default action of the element (button or link) and show a pop up message (with a javascriptâs âalert()â or with a modal, or any other choice).
After the message, with jQuery you call the app that sends the mail (using ajax you can wait for a response)
When your app sends back a confirmation via ajax, you remove the pop up message with the client.
This option lets you catch a message even if the mailing fails, but itâs a bit tricky to implement on scriptcase.
Second option:
Iâve done something like this:
1.- I create a control app on scriptcase that receives any variable needed for the message (trough variable or a field)
2.- On the main app, I add a âbuttonâ of link type and link it to the control app.
3.- Set the target of the link to a modal, so the main app shows a modal with the control inside.
4.- A control app must have at least one field, so if I process the mail with variables, just add a label field with your message (âA mail will be sent to [your-variable-name]â).
5.1.- If you like your app to require a âclick to acceptâ action, OnValidate event of the control, I process the sc_mail_sent and after that a sc_exit() i.e. I exit the control app after the mail is sent.
5.2.- If you like it to be âautomaticâ you have to add some jquery delay that triggers the âsendâ event of the control app
I hope it helps!
Thank you Daniel for your explanations. Yes, I add the sc_mail_send in php codefield from a button and so the message appears after execution.
Your suggestions are good. I try the second option with the control app.
If I try 5.1 with âclick to acceptâ, I have the same problem, that the user see no âprocessing messageâ after clicking the button.
The automatic of 5.2 seems the best, but I have yet no idea for solvingâŚ
Regards
Hamu
This is just a trick. In the control app you showed the âSending mailâ message, but the [Accept] button stills there (in fact, the message comes before the command is executed).
Then the user clicks the button. The command launches and then you can catch any error message and show it. If no error occurs, then automatically exit the control app (as if the message closed automatically)
Yes, it does not do what you were thinking at first, but the user sees the control as a message and not as the sender (is just perception, and I admit, a bit of cheating :P)
If you pass the mouse over the ok button, youâll see that the action triggers a javascript function in the control (something like):
javascript: nm_atualiza('alterar');
If you launch this javascript function, the form will send.
Back on the scriptcase editor, you add some javascript to the form via an echo on the OnLoad event of the control
if( ! isset([var_prevent_cycle]) ){
echo "<script>
\$( document ).ready(function() {
setTimeout(function(){
nm_atualiza('alterar');
}, 2000);
});
</script>";
[var_prevent_cycle] = "printed"; // If the form gets loaded again, it wont print the javascript unless you unset the [var_prevent_cycle] variable
}
What this does is:
1.- echoes some html to the front end
2.- This HTML will actually be a script tag
3.- The script will use jquery to wait for the document to be fully loaded ($(document).ready()
4.- The .ready will launch a setTimeout wich after 2000 ms will launch the nm_atualiza() function.
5.- After the 2000ms, the OnValidate will happen. There you execute the sc_send_mail.
5.1- If the mails is successful, destroy the variable [var_prevent_cycle] (so the control app will work the next time
5.2- If it doesnât succeed, show a message (on the onValidateFailure) but leave the variable [var_prevent_cycle] so it wont re launch the timeout.
You might need to figure out some little details Iâm not seeing right now, but thatâs the idea.
If you make it work, share here what other issues you had to resolve so any one can learn from!
Good luck
Wondering if you came up with a solution to trap the errors from sending mail?