|
Posted by chotiwallah on 11/05/48 11:28
Dikkie Dik wrote:
> Thejo wrote:
> > Hi all,
> >
> > I started programming in PHP recently and have a query about empty
> > $_POST arrays. I can see two scenarios when this could happen.
> >
> > 1. When some tries to directly load the page to which data is being
> > posted (for example, opening www.foo.com/xyz.php directly when a form
> > action is xyz.php)
i generally use a hidden field to detect a submit.
> > 2. When the user clicks the submit button without entering anything.
then the post array is not empty, the elements just contain empty
strings. the validation routine of the form data should take care of
that.
> >
> Then (if method=post), the submit button itself is ported (it has a name
> and a value).
careful here, ie does NOT submit the button if the form is submitted
using the return key.
> > I am aware that Javascript validation can take care of the second case,
> > but it's unreliable. What is the accepted way of handling the above
> > situations on the server side?
> > Do I just reload the calling page if the array is empty?
> >
> > Thanks,
> > Thejo
> >
>
> It is not uncommon to omit the action attribute on the form of a PHP
> webpage. This means that the same page is used for displaying of the
> form AND for processing the results. This can be handy for continuous
> adding or giving the user a second change to correct the data posted.
> Off course, an if-statement gives you the power to have the same page
> behave totally different depending on what was posted.
>
micha
[Back to original message]
|