Just running a QACTION and Preventing Double Submission too!
Fri, 05/29/2009 - 13:24
Please guys, must I attach an action to an event and wait for that event to trigger before my action is taken?
I have an action I want to occur as soon as the QPanel is loading like this:
<?php
QAlertAction('This is a test of the "QAlertAction" example.\r\nIsn\'t this fun? =)');
?>Can I achieve this? Please?
Secondly please, how do I prevent my forms from being submitted twice and processed twice on my server. If the user hits the refresh button after performing one action, it is repeated again and thus my dbase is filled with redundant data. How do I curb this? Please.

I'm not really clear of what you want to achieve. However I'll try to give an example
First: You can use delay eg.
$this->btnShow->AddAction(new QClickEvent(), new QToggleDisplayAction($this->pnlName));$this->btnShow->AddAction(new QClickEvent(500), new QAlertAction('bla bla bla'));
Second: you may use your own validation to check the existing data before writing it. It depends on your database design.
Perhaps you can give some code snippets so we can have a look more detail :)
First: if you just want to run a javascript action, do QApplication::ExecuteJavaScript(). For example,
QApplication::ExecuteJavaScript("alert('hello world');");Second: attach two actions to your button. First, a QJavaScriptAction() that disables the button. Second, a QAjaxAction() that performs your desired form submission processing. Don't forget to re-enable the button afterwards (for example, if the form failed validation, you want to allow the user to re-submit).
At least you should put the 'new' keyword in front of QAlertAction, since it is an object. Do you need this:
QApplication::DisplayAlert('the text for the alert box');Otherwise, please have a look in the javascript example in the examples web site; http://examples.qcu.be/assets/_core/php/examples/events_actions/javascri...
Hey! Breathing! Thanks Guys.
Revvi, Alex, Rtaconni, thanks so much guys but how about preventing the double form submission? Can any body bail me out on that. After submission of the form, if the user hits the refresh or reload button on the browser, it goes all over again submitting the whole form and recording data twice in my database. I hate this as it is obscuring accountability. Please help me gurus.
Well, to be fair, every single e-commerce site on the planet has a problem with the browser Refresh button. That's exactly why they say "don't press the refresh button!" :-)
How to avoid this: it's hard.
One way you could do this is to generate a "transaction ID" when first rendering a page; it serves as a "lock". Whenever the user submits a form, that transaction becomes "closed". Further submissions will check whether the transaction is "open", and if not, they'll have to abort.
Thanks much Alex.
That's just what I am doing now but men, its a real difficult task! That's why I need a javascript alert action to at least warn each user whenever they try it so they could guard against it later. I am using transaction IDs and at least its pretty working fine in this case, for now.
I'ld give you guys a link to the project I'm writing soon so you could see it. :D
You've helped me much. I appreciate, yes I do.
Take a look at the deletion confirmation in the default form drafts. You should be able to do the same for the save button.