_POST not carrying over values, across includes
Moderator: General Moderators
_POST not carrying over values, across includes
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.
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.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: _POST not carrying over values, across includes
They actually do carry over, maybe it's because $_POST is a superglobal. Paste the script in question.Why don't the _Posts carry over to the included php script?
“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
Re: _POST not carrying over values, across includes
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:
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:
Not sure what I'm doing wrong here?
The form code(truncated) is:
Code: Select all
<form action="train-finder-results.html" method="POST">
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?
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: _POST not carrying over values, across includes
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
Re: _POST not carrying over values, across includes
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.
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.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: _POST not carrying over values, across includes
Here is how i see it
Now i have another page called page.php. This is the action page that will be display when the form is called
On third_page.php i have the following code
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.
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
?>Code: Select all
<?php
// here i include the page which will display the value of
// $_POST['fieldName']
include 'third_page.php';
?>Code: Select all
<?php
echo $_POST['fieldName'];
?>“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
Re: _POST not carrying over values, across includes
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 =)
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 =)