You are here: Re: [PHP] Forms on PHP « PHP « IT news, forums, messages
Re: [PHP] Forms on PHP

Posted by PHPDiscuss - PHP Newsgroups and mailing lists on 10/09/64 11:05

Leon Poon wrote:

> Refer to the following line numbers:

> 01 > <?php
> 02 > // Start of PHP code - Extract values from form.
> 03 > /* Other values read */
> 04 > $n=$_POST['n'];
> 05 >
> 06 > // Pass the data from the form to lightcurve_csharp
> 07 > $command="./lightcurve_csharp $a $i $e $lomega $bomega $lambda $n";
> 08 > $result=`$command`;
> 09 >
> 10 > $form_submitted=$_POST['form_sumbitted'];
> 11 > if (isset($form_submitted)) {
> 12 > if ($form_submitted) {
> 13 > echo 'The form has been submitted<br>';
> 14 > unset($form_submitted);
> 15 > }
> 16 > } else
> 17 > echo 'The form has not been submitted<br>';

> When the user first load the page, no data was posted. So there was no
> $_POST['form_sumbitted'] available. Line 10 will cause $form_submitted to
> contain the NULL value (I think). $form_submitted will evaluate to FALSE at
> line 12. Thus it will not display any message.

> By the way, by doing line 10, $form_submitted would have been set regardless
> whether there is $_POST['form_sumbitted'], and line 11 will evaluate to TRUE
> always. Thus you will never ever see the 'form not been submitted' message.

> Anyway, when you posted for the first time, $_POST['form_sumbitted'] is
> available. The 'The form has been submitted<br>' message will be printed.
> After that, when you press Reload button on the browser, the post data will
> once again be sent from the user. (This is the behaviour of reloading a
> posted page. In Internet Explorer there should be a message dialog box
> asking the user whether to resend form data in order to refresh.) Reposting
> the data during the reload means that there will be
> $_POST['form_sumbitted'], thus once again the 'form hass been submitted'
> message.

> In order to prevent this from happening, you should do a header('Location:
> success-page.php') on a successful submit. This is so that at the redirected
> page, the user would not have resent data even if he press the Reload
> button.

> Hope this helps



> -Leon

Many thanks - at the top of the file I put in the code:

if ($_POST['submit'])
header('Location: .../submitted.php');

where further down in the form I have name="submit" for the submit button.
This goes to a new page submitted.php. The code is in fact now at
http://proteus.as.arizona.edu/~csharp/lightcurved.php .

No doubt there is still a way of writing back to the original page after
the submit button has been clicked, but I can't see an easy way, so this
will have to do for now. A work-around is to do it in frames, and write
to a frame at the bottom so that it appears to be in the same page.

Christopher Sharp

 

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

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