Hi,
I'm using the include statement to execute one PHP script from another, but I'm using smarty to separate HTML from PHP. The HTML is executed and the form posts back to the PHP file. The PHP code completes but does not return to the PHP script from which it was included.
What am I doing wrong?
Thanks,
Sean
5 3505 Atli 5,058
Expert 4TB
Hi Sean.
The include() function inserts the PHP code from the file you specify into the current code. So if the file you include has has an exit() or header() function which causes the code to stop executing or causes the page to be redirected, the rest of the original code, after the include() function will never get executed.
Could you post the code that is causing the problem? It may help us understand exactly what is going on.
Hi,
Yes of course. I didn't before because it would be overkill to include all my code. Here is the code relating to what I want to code.
UserSubmitJob.php -
include( 'UserJobContactInfo.php' );
-
var_dump( $_POST );
-
UserJobContactInfo.php -
if( !isset( $_POST['submitContactInfo'] ) )
-
{
-
$selfChanged = "UserJobContactInfo.php";
-
$smarty->assign( 'selfChanged', $selfChanged );
-
$smarty->display('jobs/UserJobContactInfo.tpl');
-
}
-
else
-
{
-
// Do lots of stuff here
-
echo "Here";
-
}
-
The include works and
is executed. This script uses smarty to display a HTML form which when completed posts data back to
. The comment do lots of stuff here replaces the processing on that data, which is not important here. The code completes and the echo is printed but execution doesn't return to
and the var_dump is never executed. Do I need an exit statement?
Hope this makes sense.
Thanks,
Sean
Atli 5,058
Expert 4TB
Ok, I see.
I think the problem is that you are posting the form data to 'UserJobContactInfo.php' rather than 'UserSubmitJob.php'.
When the form is submitted, it redirects the browser, calling 'UserJobContactInfo.php', bypassing the include() in 'UserSubmitJob.php' and going straight to 'UserJobContactInfo.php'. So the var_dump() function is called when the form is printed, there is simply nothing to print.
Try changing the form, having it submit it's data to 'UserSubmitJob.php' instead of 'UserJobContactInfo.php'.
Hi,
Yes I could change the form action in the smarty template for 'UserJobContactInfo.php' to 'UserSubmitJob.php' but that would mean copying the form processing data from UserJobContactInfo.php which is a script that I want to reuse.
By not changing the HTML form it posts to UserSubmitJob.php. By changing it posts to UserJobContactInfo.php which is what I want but UserJobContactInfo.php appears to complete. Printing the string here but doesn't go back to UserSubmitJob.php from which it was included.
Sean
Ok, I see.
I think the problem is that you are posting the form data to 'UserJobContactInfo.php' rather than 'UserSubmitJob.php'.
When the form is submitted, it redirects the browser, calling 'UserJobContactInfo.php', bypassing the include() in 'UserSubmitJob.php' and going straight to 'UserJobContactInfo.php'. So the var_dump() function is called when the form is printed, there is simply nothing to print.
Try changing the form, having it submit it's data to 'UserSubmitJob.php' instead of 'UserJobContactInfo.php'.
Atli 5,058
Expert 4TB
Hi,
Yes I could change the form action in the smarty template for 'UserJobContactInfo.php' to 'UserSubmitJob.php' but that would mean copying the form processing data from UserJobContactInfo.php which is a script that I want to reuse.
By not changing the HTML form it posts to UserSubmitJob.php. By changing it posts to UserJobContactInfo.php which is what I want but UserJobContactInfo.php appears to complete. Printing the string here but doesn't go back to UserSubmitJob.php from which it was included.
Sean
OK. This is getting a little confusing...
When you submit a form, your browser is redirected, creating an entirely new Request. Your include, which was created in the previous request, is thrown away, forgotten.
You can submit your form to the 'UserSubmitJob.php' without changing a thing in your code. It will include the 'UserJobContactInfo.php' and run the form processing code that you put there. (This is all based on the code you posted, of course)
The include() function imports the code of the file you specify into the current code and executes it.
And by the time you see anything in your browser, all the PHP code has been executed. What happens after you post your form has nothing to do with the code executed before it was shown.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bhennon |
last post by:
Hey all,
I have a small php script that calls a random image at the following
page.
http://www.2006ymcanationals.com/random.php
IT WORKS IF I go directly to the above link.
I am trying to...
|
by: Shailan |
last post by:
Hi
Im having trouble with the following code that seems to be behave
differently when called from the browser as opposed to the command
line. The calling script is a cgi that forks, with the...
|
by: Michael Winter |
last post by:
In an attempt to answer another question in this group, I've had to resort
to calling the DOM method, Node.removeChild(), using a reference to it
(long story...). That is, passing Node.removeChild....
|
by: Mark C. |
last post by:
I'm trying to call a batch file that I've built using the FileSystemObject
and CreateObject("Wscript.Shell"), oShell.Run... in an asp script.
Naturally, I can get the script to work from a command...
|
by: Jakej |
last post by:
I've been using a javascript in an html file for a banner slider, and
it works as desired. But I'd like to use it on more than one page and
it would be great if I could transfer the code to a .js...
|
by: Stefan Barlow |
last post by:
I have a mechanism that performs a server transfer to another page that uses
the same codebehind class if an alternate page URL exists in the application
variables.
My problem is there is an...
|
by: monomaniac21 |
last post by:
hi i want to be able to trigger a javascript style popup alert in php
(i want a message displayed on the actual page) is this possible?
|
by: Adam Smith |
last post by:
Hello,
How can I call or trigger an external javascript twice in a form?
I have
<script language="JavaScript" src="country_state.js"
name="Country_State">
<script type="text/javascript"...
|
by: Newbie Coder |
last post by:
Hello all
I have 3 functions in a javacrip file (MyScript.js), which is added to an
ASP.NET 2.0 project
1) no right-click
2) no select text (copy...)
3) History.Back()'
How do I call...
|
by: Catherine Moroney |
last post by:
I have one script (Match1) that calls a Fortran executable as a
sub-process, and I want to write another script (Match4) that
spawns off several instances of Match1 in parallel and then waits...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |