Reply to Is it possible to handle form submission in the same file?

Your name:

Reply:


Posted by webmasterATflymagnetic.com on 01/23/08 23:58

If you use Javascript you can set the FORM ACTION to call a function
within the same file (or at least within a *.js file that was
previously loaded into that file). Can you do something similar for
PHP? The code below (which I got from http://www.webmonkey.com) is
supposed to do this, but it doesn't work for me.

So I'm clear on this -- when this runs as there is no variable called
$submit the if true part will not execute, but instead the if false
(=else) part will run instead, showing the HTML FORM. This is indeed
what happens. But I understand that the code in the action attribute
(ie <?php echo $_SERVER['PHP_SELF']; ?>) will cause the file to be
reloaded. However as the user has clicked the submit button the
variable $submit will now have a value and so the if true part of the
if statement will execute.

It doesn't work for me -- I put data into each of the fields and then
click the button. The data disappears, but I don't get the
'name=value' list that I was expecting.

Is this valid code? If so why isn't it working? If not, what do I need
to do to change it?

Any help will be appreciated.

<html>
<body>

<?php
if ($submit) {
// process form
while (list($name, $value) = each($HTTP_POST_VARS)) {
echo "$name = $value<br>\n";
}

}else{
// display form
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
First name:<input type="Text" name="first"><br>
Last name:<input type="Text" name="last"><br>
Address:<input type="Text" name="address"><br>
Position:<input type="Text" name="position"><br>
<input type="Submit" name="submit" value="Enter information">
</form>
<?php
}
?>
</body>
</html>

[Back to original 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

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