You are here: Re: How to redirect after form submit? « PHP Programming Language « IT news, forums, messages
Re: How to redirect after form submit?

Posted by David Haynes on 06/12/06 23:19

deko wrote:
>> The form processing should be the *first* thing in the file.
>> Something like:
>>
>> DOCTYPE ...
>> <?php
>> if( isset($_POST['foo'] ) {
>> // do form processing
>>
>> if( $isValid ) {
>> header();
>> exit;
>> }
>> }
>> ?>
>> <form action="..." method="POST">
>> ...
>> <input type="text" name="foo" size="10" maxlength="255">
>> <input type="submit">
>> </form>
>
> Thanks, that helped. I am getting the correct redirect behavior now.
>
> But I still have a couple of questions...
>
> Here's how it looks now:
>
> ------------------------
> <?php
> $message = $_POST['message'];
> $email = $_POST['email_address'];
> if (!empty($message) && !empty($email))
> {
> header("Location:http://bubba/send-confirm.php");
> exit;
> }
> ?>
> DOCTYPE
> <html>
> ...
> ...
> <form action=<?php include "myscript.php" ?> method="POST">
> <input name="email_address" type="text" size="10" maxlength="255">
> <textarea name'"message" rows="12" cols="22"> </textarea>
> <input type="submit" value="Send">
> </form>
> ...
> ...
> </html>
> --------------------------
>
> Does my form look correct?
>
> What form attributes are required (which are optional) - name, type,
> method... ?
>
> Am I properly referencing "myscript.php"? Do I need the include statement?
>
> Thanks again for you help!
>
>
Assuming that all this is saved in a file named 'myscript.php', then
your form should look like this:

<form action="myscript.php" method="POST">
<input type="text" name="email_address" value="<?php echo
$_POST['email_address'];?>" size="10" maxlength="255">
<textarea name="message" rows="12" cols="22">
<?php echo $_POST['message'];?>
</textarea>
<input type="submit" value="Send">
</form>

The <?php echo bits cause the form to redisplay what was entered since
the only times the user will see the form are a) if this is the first
time or b) if there was some error in processing the values supplied to
the form.

The include statement is used to read in code from another file and
merge it into the current image and then interpret it. In a form action,
you are just specifying the name of the php file that the browser should
call when the submit action of the form is triggered.

The typical minimum set of attributes on <input> tags are type and name.

-david-

 

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

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