Page 1 of 2
php include question.
Posted: Wed Jan 03, 2007 3:59 am
by Nicole
Hi, anyone know if you can send a form action to a php include or php function instead of php elsewhere? So that it will execute code when submit is clicked? I am trying to get echo's to appear on the web page when a form is sent with php instead of black text on the blank page in server land. If anyone knows of a way to get an echo on the web page itself please let me know, thank you very much.
Posted: Wed Jan 03, 2007 4:03 am
by Oren
Of course you can, but what exactly you want to do? Please be more clear - people shouldn't read your post more than twice to understand what you want to do.
Posted: Wed Jan 03, 2007 3:04 pm
by Nicole
I just want when a submit button is clicked on for the echo message to appear on the web page it is on. Instead of the blank white page that echo's normally appear on.
Thats it.
The submit sends to php on the same page or to php on another page elsewhere.
The php sends all the form fields to an email address. Thanks.
Posted: Wed Jan 03, 2007 3:41 pm
by snowrhythm
i think you want to set the action to $_SESSION['php_self']...so in the form tag, write action="$_SESSION['php_self']"
Posted: Wed Jan 03, 2007 3:52 pm
by jyhm
Just to chime in on what snowrhythm said,
I think what you want to do is make sure the form action is set to the same page that the form is on.
Posted: Wed Jan 03, 2007 4:06 pm
by snowrhythm
Nicole wrote:...Instead of the blank white page that echo's normally appear on.
- that's absolutely classic.
Posted: Wed Jan 03, 2007 4:08 pm
by jyhm
snowrhythm wrote:- that's absolutely classic.
darn those echo's !
Posted: Wed Jan 03, 2007 4:49 pm
by Nicole
LOL, you guys are busting me up. I love your humor. I like your new approach, hope it works. I'm getting an error on the session action="$_SESSION['php_self']" Am I supposed to put the page address in the php _self spot?
Using the same address seems to be doing something. But its not sending to the email when the submit is pushed. I think its because it needs to look for the specific email code only on the page when the submit is pushed. As it is now, its looking at the code on the whole page.
Anyway to have it look at the email code only on the page without trying to launch the rest?
Or maybe you have ideas with this to get an echo to appear on the same page. When the submit button is pushed the echo appears on the same page. What do you think? I tried this though, nothing happened. I think I have the if post written incorrectly. Anyone know the right way?
if (isset($_POST[submit])
{
echo "submission successful";
}
Posted: Wed Jan 03, 2007 5:02 pm
by boo_lolly
you're not supposed to put the actual url instead of 'php_self'. can you post your whole form? you're probably missing something like...
Code: Select all
$input_field1 = $_POST['input_field1'];
$input_field2 = $_POST['input_field2'];
try this in your form tag...
Code: Select all
<form action="<? echo $_SERVER['php_self']; ?>" method="post">
you may get away with
Code: Select all
<form action="<? $_SERVER['php_self']; ?>" method="post">
see if that works.
Posted: Wed Jan 03, 2007 5:04 pm
by jyhm
You'll have to be more specific,
try posting all your code so we can see what is wrong.
Be careful when posting code on the boards.
viewtopic.php?t=8815
Line 9
Posted: Wed Jan 03, 2007 5:40 pm
by mickd
Are you guys refering to
?
$_SESSION['php_self'] shouldn't exist unless you have it set.
Also, a more safer way to post a form to the same page is use #
Code: Select all
<form method="post" name="some_form" action="#">
...
</form>
Posted: Wed Jan 03, 2007 5:58 pm
by boo_lolly
mickd wrote:Are you guys refering to
?
$_SESSION['php_self'] shouldn't exist unless you have it set.
Also, a more safer way to post a form to the same page is use #
Code: Select all
<form method="post" name="some_form" action="#">
...
</form>
as far as i know, $_SERVER['php_self'] is a global variable, it will never change, meaning you can use it anywhere on any page and it will always call itself. using '#' as the form action will only bump you up to the top page. i don't think it will do anything else. possibly, it won't even post the input fields.
Posted: Wed Jan 03, 2007 5:59 pm
by feyd
I'd suggest you search the forums for the many times we've talked about PHP_SELF.
Posted: Wed Jan 03, 2007 6:07 pm
by snowrhythm
Nicole wrote: I think I have the if post written incorrectly. Anyone know the right way?
if (isset($_POST[submit])
{
echo "submission successful";
}
yeah, you need single quotes around the submit. so it should look like this: $_POST['submit']
Posted: Wed Jan 03, 2007 6:20 pm
by Nicole
OK here ya go, but do I even need all this, if an echo can appear when the button is pushed?
I'm game to try it.
Code: Select all
<?php
while ($row = mysql_fetch_array($result))
//other stuff up here that works fine. That pops up this form.
{
//this following form works fine too and sends to an email, when the email php is listed on a separate page. ( I include that under this so you can see it.) But when I try to include the email form within like this, it won't send to the email when the submit button is pushed.
$mailto = 'emailaddress@whatever.com';
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'>
<input type='text' name='sendingfield' size=15>
<input type='submit' name='submit' value='submit' /></form>;
$another = $_POST['sendingfield']; //field that sends to email when submit is pushed'
$subject = 'Subject' for email;
$uself = 0;
$sep = (!isset( $uself ) ¦¦ ($uself == 0))? '\r\n' : '\n' ; //puts fields into email correctly.
$messageproper = 'Filled field listed in email field: $another\n';
mail($mailto, $subject, $messageproper, 'From:' . $sep . 'Reply-To:' . $sep); ";}}
//maybe I need an "if" echo down here if the submit button is pushed.
?>
_______________________________________________________________________
//And you probably don't need this, but if you want to look at it.
Here's how it looks when sending the field to the email form on a separate page.
echo "<form action='sendemail.php' method='post'>
<input type='text' name='sendingfield' size=15>
<input type='submit' name='submit' value='submit' /></form>";
And the sendemail.php on separate page that sends field to email.
$mailto = 'emailaddress@whatever.com';
$another = $_POST['sendingfield']; //field that sends to email when submit is pushed'
$subject = 'Subject' for email;
$uself = 0;
$sep = (!isset( $uself ) ¦¦ ($uself == 0))? '\r\n' : '\n' ; //puts fields into email correctly.
$messageproper = 'Filled field listed in email field: $another\n';
mail($mailto, $subject, $messageproper, 'From:' . $sep . 'Reply-To:' . $sep); ";}}
?>
Whoaaa, thats a lot of color.