Need help with FORM/CGI. Simple!? request!?

J

Jeffrey Silverman

<Whew>

You've all bee right in different ways. The help desk ticket returned
that same info: DW html code was mucking up the page, script couldn't
run...

I fixed that, DW has a view that shows whether or not the code is being
accepted as PHP or HTML. That part is done, and PHP appears to be
functioning on the warped site just fine...

Now, when I try to process the form:
http://www.vacavillemultimedia.com/contact.html

Using the PHP that was kindly written by Mr. Finkle:
http://www.vacavillemultimedia.com/form_processor.html

I get this error message:

Warning: Cannot modify header information - headers already sent by
(output started at
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php:7)
in
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php
on line 15

This is the script I am using:

<html>
<head>
<title>form_processor</title>
</head>
<body>
<center>
<?

foreach ($_REQUEST as $key => $value){
$message .= $key .' = '. $value."\n";
}

mail("(e-mail address removed)","Email Form",$message);

header("Location: confirmation.html");
exit;

?>

</body>
</html>


So the PHP is obviously being interpreted, but there is some error in
the script, I guess...

If there's anyone who can guide this novice just one step further, I
know it is you guys...

And I thank everyone again for my education with scripts, PHP, CGI and
the like. I am hoping I can use this knowledge to help out someone new.

Thanks again...

Pete

Get rid of EVERYTHING before the first <? and EVERYTHING after the last ?>

"EVERYTHING" includes whitespace. The resulting file should look like
this:
<?

foreach ($_REQUEST as $key => $value){
$message .= $key .' = '. $value."\n";
}

mail("(e-mail address removed)","Email Form",$message);

header("Location: confirmation.html");
exit;

?>

Remember, this is a pure PHP processing page and there need be (in fact,
there must not be) any HTML code in there at all.

Read a little more on how PHP works at http://www.php.net

http://us4.php.net/tut.php

later...
 
P

Peter Lozzi

Get rid of EVERYTHING before the first <? and EVERYTHING after the last ?>

"EVERYTHING" includes whitespace. The resulting file should look like
this:
<?

foreach ($_REQUEST as $key => $value){
$message .= $key .' = '. $value."\n";
}

mail("(e-mail address removed)","Email Form",$message);

header("Location: confirmation.html");
exit;

?>

Remember, this is a pure PHP processing page and there need be (in fact,
there must not be) any HTML code in there at all.

Read a little more on how PHP works at http://www.php.net

http://us4.php.net/tut.php

later...

Wait... Actually the PHP script is now successfully running... We
fixed that part, thanks to you... (I am actually receiving an email
when the user submits now!)

(Also thanks for the link to php.net...)

I think there's an error in the script somewhere now... So when you
click "submit" the page does indeed get sent to the specified email
address, but the following error message appears (instead of having the
user redirected to confirmation.html)

Error meesage displayed in browser after user clicks "sumbit":

Warning: Cannot modify header information - headers already sent by
(output started at
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php:7)
in
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php
on line 15

So the PHP script IS running, and I am receiving an email... It just
isn't obvious to me why the user wouldn't be directed now to the
"confirmation.html" page...

Thanks again... (Wow, this PHP stuff is way harder than I thought.
WAY new respect for all you coders!)

Pete
 
J

Jeffrey Silverman

Error meesage displayed in browser after user clicks "sumbit":

Warning: Cannot modify header information - headers already sent by
(output started at
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php:7)
in
/raid/ATL/vips/home0/pmlozzi/vacavillemultimedia.com/form_processor.php
on line 15

So the PHP script IS running, and I am receiving an email... It just
isn't obvious to me why the user wouldn't be directed now to the
"confirmation.html" page...

Thanks again... (Wow, this PHP stuff is way harder than I thought.
WAY new respect for all you coders!)

It will do everything up to the "header()" function. So you should get
your email just fine.

header() is a way for PHP to redirect the user *back* to the page he was
just on without ever clicking on anything, seamlessly. However, it only
works if there is no output of any kind preceding it. The email function
isn't output -- it is just a function that has some side effects. The main
side effect being sending you email. The output of any PHP script would
be the HTML back to the browser.

So, once again, get rid of everything that is NOT PHP code and the thing
will work without errors.
 
P

Peter Lozzi

It will do everything up to the "header()" function. So you should get
your email just fine.

header() is a way for PHP to redirect the user *back* to the page he was
just on without ever clicking on anything, seamlessly. However, it only
works if there is no output of any kind preceding it. The email function
isn't output -- it is just a function that has some side effects. The main
side effect being sending you email. The output of any PHP script would
be the HTML back to the browser.

So, once again, get rid of everything that is NOT PHP code and the thing
will work without errors.

Jeff,

Wow, I am really feeling helpless here. I just spent about an hour on
the PHP link you sent, and I played with the script for awhile, seeing
if I could figure this out myself, I cannot.

I read and reread your post a few times, and I truly appreciate that
you aren't spoon feeding this stuff to me... It has inspired me to
learn a lot more about PHP than I need to or thought I wanted to, and
the knowledge will help me in the long run...

Here's what I got from rereading your post a few times:

*I do* get the email just fine, so the script commands are indeed
carried out to the "header" point. You made a comment in your post
that the header() command redirects the user back to the page they were
on seamlessly, unless there is some output preceeding it.

Well, in my case, there is preceeding input, I guess... The PHP script
is sending the info in an email to me. When I remove the header
command in the code - (example with "header" code removed from the
script):

The result of this script is: When the user clicks "submit" the
browser *does send the form data* - *transparent to the user* and the
user's browser stays on the PHP script page (/form_processor.php) with
a blank white screen. (Go to
http://www.vacavillemultimedia.com/contact.html and click "submit" to
see what I mean!)

My PHP novice assumption, there is nothing redirecting the user
*anywhere* whether back to the form they just submitted or anywheres
else...

So what I have now been looking for is a simple command in the script
to have the browser point to a page. *Any page will do at this point!*
In fact I will just create a page of some sort that says, "your form
was sent, thank you!"

What command can I include in the script to instruct the browser to
point to the page of my choosing *after* 1) the user has clicked the
submit button on the form 2) the email is with the form data has been
sent.

Now, is there a page out there with some nice ol' list of PHP script
commands? I clicked through the links you sent, and read some of them
extensively, and didn't just find a "table" of PHP commands I could use
in my script...

JUST A LITTLE MORE HELP! THANK YOU ALL SO MUCH!

Pete
 
B

Beauregard T. Shagnasty

Quoth the raven Peter Lozzi:
On 2004-09-17 19:08:42 -0700, Jeffrey Silverman <[email protected]>
said [the script below]:

Here's what I got from rereading your post a few times:

*I do* get the email just fine, so the script commands are indeed
carried out to the "header" point. You made a comment in your post that
the header() command redirects the user back to the page they were on
seamlessly, unless there is some output preceeding it.

Well, in my case, there is preceeding input, I guess... The PHP script
is sending the info in an email to me. When I remove the header command
in the code - (example with "header" code removed from the script):

===== remove all between here ========== and here =====

And put the header() line back in. That is what will bring up the
"thanks for submitting" page.
The result of this script is: When the user clicks "submit" the browser
*does send the form data* - *transparent to the user* and the user's
browser stays on the PHP script page (/form_processor.php) with a blank
white screen. (Go to http://www.vacavillemultimedia.com/contact.html
and click "submit" to see what I mean!)

It stays on the PHP "page" because the script failed. You must remove
the HTML from the script.
My PHP novice assumption, there is nothing redirecting the user
*anywhere* whether back to the form they just submitted or anywheres
else...

...because you removed it?
So what I have now been looking for is a simple command in the script to
have the browser point to a page. *Any page will do at this point!* In
fact I will just create a page of some sort that says, "your form was
sent, thank you!"

What command can I include in the script to instruct the browser to
point to the page of my choosing *after* 1) the user has clicked the
submit button on the form 2) the email is with the form data has been sent.

That header() line you snipped out.
....
 
P

Peter Lozzi

Quoth the raven Peter Lozzi:
On 2004-09-17 19:08:42 -0700, Jeffrey Silverman <[email protected]>
said [the script below]:

Here's what I got from rereading your post a few times:

*I do* get the email just fine, so the script commands are indeed
carried out to the "header" point. You made a comment in your post
that the header() command redirects the user back to the page they were
on seamlessly, unless there is some output preceeding it.

Well, in my case, there is preceeding input, I guess... The PHP script
is sending the info in an email to me. When I remove the header
command in the code - (example with "header" code removed from the
script):

===== remove all between here ========== and here =====

And put the header() line back in. That is what will bring up the
"thanks for submitting" page.
The result of this script is: When the user clicks "submit" the
browser *does send the form data* - *transparent to the user* and the
user's browser stays on the PHP script page (/form_processor.php) with
a blank white screen. (Go to
http://www.vacavillemultimedia.com/contact.html and click "submit" to
see what I mean!)

It stays on the PHP "page" because the script failed. You must remove
the HTML from the script.
My PHP novice assumption, there is nothing redirecting the user
*anywhere* whether back to the form they just submitted or anywheres
else...

..because you removed it?
So what I have now been looking for is a simple command in the script
to have the browser point to a page. *Any page will do at this point!*
In fact I will just create a page of some sort that says, "your form
was sent, thank you!"

What command can I include in the script to instruct the browser to
point to the page of my choosing *after* 1) the user has clicked the
submit button on the form 2) the email is with the form data has been
sent.

That header() line you snipped out.
...

That was it!

::sobbing inconsoleably::

It was because I was trusting Macromedia to send the PHP code up as it
said it was going to.

It didn't. You guys rock.

I SWEAR TO NEVER USE DREAMWEAVER TO SCRIPT AGAIN.

It works perfectly. Thank you all!

Pete
 
B

Beauregard T. Shagnasty

Quoth the raven Peter Lozzi:
That was it!

::sobbing inconsoleably::

Please don't be so hard on yourself.
It was because I was trusting Macromedia to send the PHP code up as it
said it was going to.

It didn't. You guys rock.

I SWEAR TO NEVER USE DREAMWEAVER TO SCRIPT AGAIN.

Now that you're catching on, next week you should .. oh ..
It works perfectly. Thank you all!

Your assignment for October is to write one PHP script/page that
a. displays the form to the visitor
b. processes the form and emails you
c. displays the result to the visitor

<g>
 
J

Jeffrey Silverman

Jeff,

Wow, I am really feeling helpless here. I just spent about an hour on
the PHP link you sent, and I played with the script for awhile, seeing
if I could figure this out myself, I cannot.

I read and reread your post a few times, and I truly appreciate that
you aren't spoon feeding this stuff to me... It has inspired me to
learn a lot more about PHP than I need to or thought I wanted to, and
the knowledge will help me in the long run...

Here's what I got from rereading your post a few times:

*I do* get the email just fine, so the script commands are indeed
carried out to the "header" point. You made a comment in your post
that the header() command redirects the user back to the page they were
on seamlessly, unless there is some output preceeding it.

Well, in my case, there is preceeding input, I guess... The PHP script
is sending the info in an email to me. When I remove the header
command in the code - (example with "header" code removed from the
script):


The result of this script is: When the user clicks "submit" the
browser *does send the form data* - *transparent to the user* and the
user's browser stays on the PHP script page (/form_processor.php) with
a blank white screen. (Go to
http://www.vacavillemultimedia.com/contact.html and click "submit" to
see what I mean!)

My PHP novice assumption, there is nothing redirecting the user
*anywhere* whether back to the form they just submitted or anywheres
else...

So what I have now been looking for is a simple command in the script
to have the browser point to a page. *Any page will do at this point!*
In fact I will just create a page of some sort that says, "your form
was sent, thank you!"

What command can I include in the script to instruct the browser to
point to the page of my choosing *after* 1) the user has clicked the
submit button on the form 2) the email is with the form data has been
sent.

Now, is there a page out there with some nice ol' list of PHP script
commands? I clicked through the links you sent, and read some of them
extensively, and didn't just find a "table" of PHP commands I could use
in my script...

JUST A LITTLE MORE HELP! THANK YOU ALL SO MUCH!

Pete

GET RID OF ALL THE HTML!!!!!

Get rid of <html>
get rid of <head> and everything in the head
get rid of <title> and all the text in the title
get rid of <p>, <b>, <center>, plain text, everything!!!!!!!!!!!!!!!

KEEP ONLY THE STUFF BETWEEN <? and ?>

I'm only yelling because I think I said this at least twice already. I
realize you are a newbie, so please don't take it personally!
 
P

Peter Lozzi

GET RID OF ALL THE HTML!!!!!

Get rid of <html>
get rid of <head> and everything in the head
get rid of <title> and all the text in the title
get rid of <p>, <b>, <center>, plain text, everything!!!!!!!!!!!!!!!

KEEP ONLY THE STUFF BETWEEN <? and ?>

I'm only yelling because I think I said this at least twice already. I
realize you are a newbie, so please don't take it personally!

PANTS! You rock. I truly appreciate your patience. I am indeed a
newbie, but a capable one. I just had to let go of DW. I won't look
back, I swear!

Pete
 
J

Joel Shepherd

PANTS! You rock. I truly appreciate your patience. I am indeed a
newbie, but a capable one.

That being the case, and since you're doing so well with the
bottom-posting, might you also be able to learn how to trim out material
not relevant to your response before clicking the "Send" button?

Thanks.
 
J

Jeffrey Silverman

PANTS! You rock. I truly appreciate your patience. I am indeed a
newbie, but a capable one. I just had to let go of DW. I won't look
back, I swear!

Pete

Thanks. You know, DW is really pretty good for some things. Just not as a
pure code editor.

later...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top