You are here: Re: multiple submit problems, Help « PHP Language « IT news, forums, messages
Re: multiple submit problems, Help

Posted by Hendri Kurniawan on 01/20/07 23:17

Jeff wrote:
> Hey
>
> I'm developing a web site using php 5.2.0
>
> So when the form submit the new data is added to the table, then the php
> script add the id of the new record into hidden field in the form: echo
> "<input type='hidden' name='property' value='".$id."' />";
>
> But when the user clicks on the refresh button in the browser, then the form
> is submitted again but my hidden field isn't sent. It looks like the browser
> don't care about the values in the form, it just send again the values from
> the last submit. To tryed to fix this problem by manually in the code add
> the $id to the $_POST array:
> $_POST["property"] = $id; - But that did NOT solved the problem. To me it
> looks like the browser discard the values I manually enter into $_POST..
>
>
> Jeff
>
>


Hi Jeff,

When you set $_POST values in PHP, they do not get sent back to the browser.
When a browser refresh a page that was fetch previously from a POST, it
will re-sent the old inputted
data -- This include any hidden fields.
So IMHO, these are my solutions:

Javascript solution (client side - conventionally used, much easier):
1 - Preventing multiple click on the submit button
2 - After form processing, do a header('Location: somefile.php') -> this
will prevent the refresh button submitting again

ID solution (server side - security, but takes server processing time):
1 - For every form, you must set a hidden field which contains a unique
ID (hidden field).
2 - Store ID in database (can be along with timestamp for cleaning up
purposes).
3 - When a form came in, check the ID against the database, if it exist,
then you have your fresh input.
4 - Delete the ID from database
5 - If the same ID come again, that means you've got an old input,
therefore you can discard it.

Hendri Kurniawan

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация