NYCPHP Meetup

NYPHP.org

[nycphp-talk] Premature submit

Mark Armendariz lists at enobrev.com
Wed Oct 3 00:24:47 EDT 2007


Anirudh Zala wrote:
> On Wednesday 03 Oct 2007 06:30:04 Urb LeJeune wrote:
>   
>> 	Had a client who twice lost existing content while making a change
>> using a CMS. Turns out the problem was they he was using a DSL line
>> and he made a change and hit the "Submit Changes" button before the
>> page had fully downloaded. Needless to say the undownloaded textarea
>> fields were empty and were written to the DB.
>>
>> 	Is there a way to disallow a form submit before the entire form
>> has downloaded?
>>     
>
> Simplest solution is to keep submit button disabled by default, and then 
> enabling it by javascript when page is loaded.
>
> Technically it can be done like this.
>
> # While writing submit tag, keep it disabled by default.
> # In the form where this button exists, put javascript code at the end of page 
> to make it enabled.
>
> By this way until page will get reloaded, Submit button would not be available 
> in press/click mode.
>
> Thanks
>
> Anirudh Zala
Agreed.  Also, in case the user hits enter to submit, you should force 
the form's onsubmit to do nothing while form is loading.

You can also check that the form was fully loaded on the server side (in 
case javascript was off or otherwise futzed with), by checking for the 
existence of the last field in the form.  As long as it's not a checkbox 
/ radio button, even if it's blank it'll still send the data.

if (array_key_exists('last_field', $_POST) === false) {
    // show form with warning or change sql to exclude field
}

Mark Armendariz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071003/5a3f580b/attachment.html>


More information about the talk mailing list