_POST not carrying over values, across includes

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

Post Reply
ff8raider
Forum Newbie
Posts: 7
Joined: Fri Dec 24, 2010 1:55 pm

_POST not carrying over values, across includes

Post by ff8raider »

Hello, I'm trying to customize a proprietary cms, to allow me to include php code into my content division.

So Basically, I have my main .php file which calls up the header, footer, sidebars, and a main content division.
The problem with this has been, every time I want a bit of custom php code in the content division, I have to reproduce the entire sidebar, headers, etc, and make a whole new php template, that gets called up when that html address is entered.

So I wrote a little script that puts a field in my cms, in which I enter the path to the .php file I want to include in my content division.

Then from my main PHP file, If there is a custom php file entered, I just include it in my content division.

So this works great, however my _Posts are not working anymore. Why don't the _Posts carry over to the included php script? They only work when I write the code directly into the main php template file. Do I need to use a session for this? I am kind of leery to use session, because I'm not sure exactly how it works.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: _POST not carrying over values, across includes

Post by social_experiment »

Why don't the _Posts carry over to the included php script?
They actually do carry over, maybe it's because $_POST is a superglobal. Paste the script in question.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ff8raider
Forum Newbie
Posts: 7
Joined: Fri Dec 24, 2010 1:55 pm

Re: _POST not carrying over values, across includes

Post by ff8raider »

Ok so my form is located in a custom script file the structure is: Page.php is my main template, and form.php is included in that template's content division.

The form code(truncated) is:

Code: Select all

<form action="train-finder-results.html" method="POST">
This has only 4 fields, which all work.

2 are: Dfrom
and: Dto

The train-finder-results.html page again has the main page.php template, and then the actual script, train_finder_results.php is included in the main template's content division.

The script is largish, but I erased it to try to simply echo the form posts:

Code: Select all

echo $_POST["Dfrom"];
echo $_POST["Dto"];

Not sure what I'm doing wrong here?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: _POST not carrying over values, across includes

Post by social_experiment »

If you want $_POST to display you need to use a php page. What happens if you change the form's action to train-finder-results.php?
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ff8raider
Forum Newbie
Posts: 7
Joined: Fri Dec 24, 2010 1:55 pm

Re: _POST not carrying over values, across includes

Post by ff8raider »

It is a php page, it's just disguised as an html. The CMS calls up the php template from the html address entered. It's really posting to the main template, page.php

If I write my echo $post_(whatever); in the page.php template, it works fine. But when I try to echo the $post_ in my script that is included in page.php, it won't work.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: _POST not carrying over values, across includes

Post by social_experiment »

Here is how i see it

Code: Select all

<?php
 // this is the page with the form on (form.php)
 <form action="page.php" method="post" >
 <input type="text" name="fieldName" />
 // rest of form
?>
Now i have another page called page.php. This is the action page that will be display when the form is called

Code: Select all

<?php
 // here i include the page which will display the value of 
 // $_POST['fieldName']
 include 'third_page.php';
?>
On third_page.php i have the following code

Code: Select all

<?php
 echo $_POST['fieldName'];
?>
When the form is submitted the name will be displayed on page.php because it echoes on third_page.php and that is included. Hth.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
ff8raider
Forum Newbie
Posts: 7
Joined: Fri Dec 24, 2010 1:55 pm

Re: _POST not carrying over values, across includes

Post by ff8raider »

Yep that's exactly what I have, I've tried posting the form to the html path, the page.php template, and the included third_page script template.

This cms is so convoluted it makes me crazy. As far as I can tell when you type in any html address on our site, a dispatch.php file is called which serves up the page.php template, and gets the specific page content from our DB, which it echoes to the content division. I've been trying to be able to have dynamic php code in our content div. I accomplished this by actually storing php code in the database, and evaluating it. But apparently that is a bit of a security problem, so I thought I'd just settle for an included content template, which I can not get to work.

I'll keep trying random things, and hopefully it will start working. I'll use a session if nothing else. Thanks a lot for your help =)
Post Reply