Re: Self-Process php forms or not?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10/4/09 9:25 AM, "MEM" <talofo@xxxxxxxxx> wrote:

> Thanks a lot. To all.
> For the moment, I'm with the redirect solution that others have pointed.
> 
> But after seen tedd example and watch Manuel videos, I'm starting to
> understand how the hidden field solution work as well. Well... I'm
> *starting* to understand I've not fully understand it yet, despite all your
> great examples. 
> 
> Because the structure of the code with hidden fields, seems quite different
> from the structure I have right now and I'm unable to make the switch.
> 
> Here is the actual structure:
> 
> if (isset($_POST['submit']))
> {
> 
>   //declare variables
>   $var = $_POST['var']; etc...
> 
>   //validate
> 
>   //process the form
>   (send e-mail or save to database etc...)
> 
>   //redirect to success page.
> } 
> else 
> {
> Echo "Sorry, couldn't process the form";
> }
> 
> <html form>
> 
> I suppose that the echo message telling "we couldn't process the form" does
> not appear when the form first loads, because the server side script is not
> requested on load, it is requested when the form submits to the php code
> presented on that same page (self). Tom Worster, is this precise?

i don't think so. if the user requests the page "a_form.php" then the server
will normally execute the a_form.php script regardless whether the form was
submitted or not. 

to display a blank form, the user probably requests a_form.php with the GET
method and probably without any GET parameters. the script will run but
$_POST['submit'] is not set. so the script you show above will echo "Sorry,
couldn't process the form". that will likely confuse the user.

in your structure you branch only two ways. i think you need three ways:

1 - the user simply arrived at the form. there is no POST data. the form was
not submitted.

2 - there is POST data. the form was submitted.

  2a - the POST data is unacceptable.

  2b - the POST data is good.


in branches 1 and 2a you send the form.

in 2b, you send some other page or a redirect.

in 1 you send the form blank.

in 2a you might fill some form elements with data from POST and add some
annotations to the form so the user knows what she or he did wrong.

> In the future, I will print tedd example, and Manuel scheme, and try to
> change the code above to accommodate hidden fields, because I still prefer
> having only one file.

one can learn a lot reading other people's code. 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux