php include question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

php include question.

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Post 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.
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

i think you want to set the action to $_SESSION['php_self']...so in the form tag, write action="$_SESSION['php_self']"
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post 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.

Code: Select all

<form action="form_page.php">
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post by snowrhythm »

Nicole wrote:...Instead of the blank white page that echo's normally appear on.


- that's absolutely classic.
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

snowrhythm wrote:- that's absolutely classic.
:D

darn those echo's !
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Post 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";
}
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post 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.
Last edited by boo_lolly on Wed Jan 03, 2007 5:56 pm, edited 2 times in total.
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post 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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

Are you guys refering to

Code: Select all

$_SERVER['php_self']
?

$_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>
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

mickd wrote:Are you guys refering to

Code: Select all

$_SERVER['php_self']
?

$_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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'd suggest you search the forums for the many times we've talked about PHP_SELF.
User avatar
snowrhythm
Forum Commoner
Posts: 75
Joined: Thu May 04, 2006 1:14 pm
Location: North Bay Area, CA

Post 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']
Nicole
Forum Newbie
Posts: 22
Joined: Thu Oct 26, 2006 7:47 am

Post 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.
Post Reply