I have a basic feedback form with a submit button.
After the "send" button is clicked, I want the user to be redirected to a
different page that says "Your message has been sent."
How do I do this?
I've tried using:
header("Locatio n:http://www.mysite.com/send-confirm.php");
But here's the error I get:
Warning: Cannot add header information - headers already sent by (output started
at ...
Here's the code:
<form action= "
<?php
$message = trim($_REQUEST['message']);
$email_address = trim($_REQUEST['email_address']);
if (empty($message ) || empty($email_ad dress))
{
$valid_message = false;
}
else
{
mail( "my email address", "feedback form", $message, "from:
$email_address" );
$valid_message = true;
}
?>"
<input name="email_add ress" type="text" size="30"/><br />
<textarea name="message" rows="12" cols="23"></textarea><br />
<input type="submit" value="Send">
</form>
<?php
if ($valid_message )
{
echo "valid message";
header("Locatio n:http://www.mysite.com/send-confirm.php");
exit();
}
else
{
echo "invalid message";
}
?>
How do I redirect after the user clicks the send button?
Thanks in advance. 13 70004
deko wrote: I have a basic feedback form with a submit button.
After the "send" button is clicked, I want the user to be redirected to a different page that says "Your message has been sent."
How do I do this?
I've tried using:
header("Locatio n:http://www.mysite.com/send-confirm.php");
But here's the error I get:
Warning: Cannot add header information - headers already sent by (output started at ...
Here's the code:
<form action= " <?php $message = trim($_REQUEST['message']); $email_address = trim($_REQUEST['email_address']); if (empty($message ) || empty($email_ad dress)) { $valid_message = false; } else { mail( "my email address", "feedback form", $message, "from: $email_address" ); $valid_message = true; } " <input name="email_add ress" type="text" size="30"/><br /> <textarea name="message" rows="12" cols="23"></textarea><br /> <input type="submit" value="Send"> </form> <?php if ($valid_message ) { echo "valid message"; header("Locatio n:http://www.mysite.com/send-confirm.php"); exit(); } else { echo "invalid message"; }
How do I redirect after the user clicks the send button?
Thanks in advance.
Put all the stuff that does output ("<form...", "<input..." ) after the
header() call.
> Put all the stuff that does output ("<form...", "<input..." ) after the header() call.
Okay, here's the header call:
<?php if ($valid_message )
{
header("Locatio n:http://www.mysite.com/send-confirm.php");
exit();
}
?>
And here's the form:
<form action="
<?php
$message = trim($_REQUEST['message']);
$email_address = trim($_REQUEST['email_address']);
if (empty($message ) || empty($email_ad dress))
{
$valid_message = false;
}
else
{
mail( "my email address", "feedback form", $message, "from:
$email_address" );
$valid_message = true;
}
?>" method="POST" name="feedback" style="font-size:12px" >
<input name="email_add ress" type="text" size="30"/><br />
<textarea name="message" rows="12" cols="23"></textarea><br />
<input type="submit" value="Send">
</form>
I no longer get the error, but the page does not redirect.
I'm sure I must be missing something simple...
I tried this:
<?php
$valid_message = true;
if ($valid_message )
{
header("Locatio n:http://bubba/send-confirm.php");
exit();
}
?>
And still got this:
Warning: Cannot add header information - headers already sent by (output started
....
Can I redirect another way?
The headers, probably, are being sent in the header section of the page.
Can this block of code be put above the DOCTYPE statement?
But then, how would the value of the $valid_message variable get set?
You must ensure that there is no blank space or empty lines, outside of the
<?php ?> braces. Any such empty space will be sent and will cause headers to
already be sent.
Make sure that <?php is the very first thing on the very first line of the
file.
deko wrote: I tried this:
<?php
$valid_message = true;
if ($valid_message ) { header("Locatio n:http://bubba/send-confirm.php"); exit(); }
And still got this:
Warning: Cannot add header information - headers already sent by (output started ...
Can I redirect another way?
The headers, probably, are being sent in the header section of the page. Can this block of code be put above the DOCTYPE statement?
But then, how would the value of the $valid_message variable get set?
> You must ensure that there is no blank space or empty lines, outside of the <?php ?> braces. Any such empty space will be sent and will cause headers to already be sent.
Make sure that <?php is the very first thing on the very first line of the file.
but what about all the html?
the page looks like this:
DOCTYPE ...
<html>
<head>
....
javascript...
</head>
<body>
<html>
all kinds of html...
<form>
<?php
....
?>
....
</form>
more html...
</html>
</body>
I want the redirect to happen only if the form is filled out correctly, so the
redirect should, I think, go just after the form code.
deko wrote: You must ensure that there is no blank space or empty lines, outside of the <?php ?> braces. Any such empty space will be sent and will cause headers to already be sent.
Make sure that <?php is the very first thing on the very first line of the file.
but what about all the html?
the page looks like this:
DOCTYPE ... <html> <head> ... javascript... </head> <body> <html> all kinds of html... <form> <?php ... ?> ... </form> more html... </html> </body>
I want the redirect to happen only if the form is filled out correctly, so the redirect should, I think, go just after the form code.
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>
-david-
deko wrote: You must ensure that there is no blank space or empty lines, outside of the <?php ?> braces. Any such empty space will be sent and will cause headers to already be sent.
Make sure that <?php is the very first thing on the very first line of the file. but what about all the html?
The html will be in the page that it is redirected to.
If you are redirecting there is no need to send any html for THIS page
because you are redirecting to a different page. the page looks like this:
DOCTYPE ... <html> <head> ... javascript... </head> <body> <html> all kinds of html... <form> <?php ... ... </form> more html... </html> </body>
I want the redirect to happen only if the form is filled out correctly, so the redirect should, I think, go just after the form code.
> 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($messag e) && !empty($email))
{
header("Locatio n:http://bubba/send-confirm.php");
exit;
}
?>
DOCTYPE
<html>
....
....
<form action=<?php include "myscript.p hp" ?> method="POST">
<input name="email_add ress" 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.p hp"? Do I need the include statement?
Thanks again for you help!
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($messag e) && !empty($email)) { header("Locatio n:http://bubba/send-confirm.php"); exit; } ?> DOCTYPE <html> ... ... <form action=<?php include "myscript.p hp" ?> method="POST"> <input name="email_add ress" 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.p hp"? 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="myscrip t.php" method="POST">
<input type="text" name="email_add ress" 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- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: shake |
last post by:
I have to develop an application sounds like this:-
User is allow to access a form (is actually a test/quiz) within a
specific time frame, let say 45 minutes. After this 45 minutes, if the
user has not yet click the submit button to submit the form, the
system need to automatically submit it.
So, can anyone teach me how to check the time out as well as how to
make the form submit automatically? Thank you very much.
|
by: Matt |
last post by:
Can form.submit() submit another form? In the following example, in
page1.asp, it is fine to submit the current form: form1.submit(), and and I
could see the value "Joe" in page2.asp. However, if I do: form3.submit(),
then it couldn't go to page2.asp. Any ideas?? Thanks!!
//page1.asp
<html>
<head>
</head>
<body onload="form1.submit()"> //OK!
|
by: Hongyu |
last post by:
I am trying to implement a simple JavaScript of redirecting my window
to a new URL upon clicking a submit button. This is an easy task except
when I have to put an input type='submit' in front of the onClick
command. It always commits the CGI action, and skip the URL redirect
part. The example code is below
<form action=mycgi.pl>
<input type='submit' name=submit value='Submit'
onClick="window.location.href='http://myserver.com'">...
|
by: Scott |
last post by:
How can I tell a form to submit itself in the code-behind
in vs.net?
In other words, in javascript I can do blah.submit() - how
do I do this in vs.net code-behind?
|
by: TheOne |
last post by:
In Asp.net web form under form tag there is action field that I am point to
some other page, and not to same web form. When I run this page it is always
pointing to itself. How do I get around this?
Here is HTML code from webform..
Thanks,
Sinisa
| |
by: jwlum |
last post by:
I have the following problem under Internet Explorer only:
1. User fills out form data (myform.php) and clicks a button that fires
myFunction()
2. myFunction() spawns a "hello, world" popup page via window.open
3. myFunction() submits the main page's form via document.form.submit()
5. User closes popup window and clicks browser's Back button to return
to form entry page
6. All the form data that the user had filled out is now blank...
|
by: prodizy |
last post by:
Hi,
In Firefox, what's the best way of tracking the form submit?
The following are two ways I tried, but they won't work if the form is
submitted through JavaScript.
Method 1: using the window.onsubmit event handler
Code: window.onsubmit=handleEvent;
|
by: gbezas |
last post by:
Hi All,
I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form).
Additionally I have defined the relavant function method in the code for details)
The issue is that when Icall targetForm._submit() method from the newSubmit() function the page I get an 'Object doesn't support this property or method' error
I am using IE...
|
by: white lightning |
last post by:
How to have <select onchange="this.form.submit()"and also a Submit
button on one form?
I have something like this:
<form action="<?php $_SERVER; ?>" method="post"
enctype="multipart/form-data" name="form1">
<select onchange="this.form.submit();" name="prod">
<option value="">Select product</option>
<option value="12">abc</option>
|
by: Frinavale |
last post by:
I've been trying all morning to cancel a form submit to the server.
I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the user clicks "yes" or "no".
This Object is attached to various HTML elements on the page (buttons, selects etc) and traps any events that they raise that cause the page to submit.
If the user has not responded, the Object should cancel the page...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |