Re: How to redirect after form submit?



making progress...

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.

I was just trying to put the form processing code into a separate file (not echo it). That's more of a managability thing - for troubleshooting, I'll put the code in-line.

I'm still having trouble getting the form action working:

<form action="<?php
//write to file for testing - production code will send email
$message_file = "/home/username/public_html/cgi-bin/messages.txt";
$message = $_POST['message'];
$fp_msg = fopen($message_file,"a");
fwrite($fp_msg, $message."\n");
fclose($fp_msg);
?>" method="post" name="feedback" >
<textarea name="message" rows="12" cols="22" maxlength="4096"></textarea></p>
<input type="submit" value="Send">
</form>

The problem is nothing gets written to messages.txt!

The redirect is working, now that I have this code at the very top of the page:

<?php
$message = $_POST['message'];
$email = $_POST['email_address'];
if (!empty($message) && !empty($email))
{
header("Location:http://www.mysite.com/send-confirm.php";);
exit;
}
?>

But does this prevent the form's in-line code in the from running?

Should I put the form action code in just above the redirect?

A couple of other questions:

Is "4096" an acceptable value for maxlength? That's about a full page of text (counting spaces).

Should I use the $_REQUEST['message'] variable? I've seen this in a couple of examples - what is it for?

Thanks!

.



Relevant Pages

  • Re: IsPostBack
    ... > loads the first time, I have code that executes once. ... > BUT I have code I want to execute ONLY the first time the page is called. ... A redirect involves doing a GET for the new page you specify ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Error on Startup (event 7022 for netevent.dll)
    ... | The first time I ran it, I didn't redirect the output. ... |>Either case you probably can't run the command and pipe to a text file ... | I just created a new full backup set yesterday. ...
    (microsoft.public.windows.server.general)
  • session variable problem
    ... I’m facing some problem can u solve it. ... I’m giving user Id and password in and submit it to page ... before redirecting to the same page, but in first time I do not received the ... value of session variable when I redirect it, ...
    (microsoft.public.inetserver.asp.general)
  • session varible problem
    ... I’m facing some problem can u solve it. ... I’m giving user Id and password in and submit it to page ... before redirecting to the same page, but in first time I do not received the ... value of session variable when I redirect it, ...
    (microsoft.public.inetserver.asp.general)