/    Sign up×
Community /Pin to ProfileBookmark

Question about Radio Buttons and Redirect

Hello all,

I’m VERY new to php programming.

I have mastered the basics of putting together a form and receiving the results of that form through email, while letting visitors land on a “thank you for filling this out” page.

My problem is now I need to program a page that allows me to receive those results by email, but at the same time, I need to redirect the user to one of three pages, based on the radio button they select.

My form is currently on an htm page. What is the easiest way to make this form email me the results (including which radio button is selected) – then redirect the user to one of those three pages using only php?

I did a search and found this code, which I inserted into the code of the php form that the page redirects to after clicking “submit”:

if($_POST[‘order’] == ‘1’) {
header(“Location: Order_1-test.htm”);
} else if ($_
POST[‘order’] == ‘2’) {
header(“Location: Order_2-test.htm”);
} else if ($_POST[‘order’] == ‘3’) {
header(“Location: Order_3-test.htm”);
}

but it gave me an error:

Warning: Cannot modify header information – headers already sent by (output started at /home/brandnew/public_html/order.php:2) in /home/brandnew/public_html/order.php on line 27

I am VERY confused and need guidance.

Please, and thank you in advance.

Phil

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@michael879Mar 05.2007 — the header() function in this case is being used to redirect the user to the page given. Headers must be sent before any html has been sent to the browser however. This error will be thrown if you have ANY html before the header() call. This includes whitespace before the <?php tag.
Copy linkTweet thisAlerts:
@mwmwnmwMar 05.2007 — Actually, that's not entirely true. You can use a simple output buffer and your redirects will work just fine. Just make sure that you open the buffer first thing on the page, then close it before your redirects....

<i>
</i>&lt;?php
ob_start();

That starts the buffer. From there you just do whatever
you want to do in the script. Once you've finished and
want to send your redirects you close the buffer just before
your redirect logic.....

ob_end_clean();

if($_POST['order'] == '1') {
header("Location: Order_1-test.htm");
} else if ($_POST['order'] == '2') {
header("Location: Order_2-test.htm");
} else if ($_POST['order'] == '3') {
header("Location: Order_3-test.htm");
}



Easy.
Copy linkTweet thisAlerts:
@philbeevauthorMar 05.2007 — Thank you both.

I combined your answers, and it worked like a charm.

My deepest appreciation and best wishes go out to both of you.

Phil
Copy linkTweet thisAlerts:
@michael879Mar 05.2007 — Actually, that's not entirely true. You can use a simple output buffer and your redirects will work just fine. Just make sure that you open the buffer first thing on the page, then close it before your redirects....
[/QUOTE]

everything I said was true.. output buffering prevents php from sending html to the browser until you flush the buffers. You still cant send headers after you have sent any html. Your right tho, I shoulda mentioned output buffering, completely forgot about it.
×

Success!

Help @philbeev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...