EE embeds not parsed when echo’d from PHP
Posted: 27 August 2008 02:04 PM   [ Ignore ]  
Summer Student
Total Posts:  5
Joined  08-27-2008

I’m a new EE user, I’m evaluating it for use with all of my companies future projects—hence we haven’t bought a license yet.

My problem: I’ve created a simple survey and I want to dump the results to a separate MySQL database. I’ve turned PHP parsing on, and set the PHP Parsing Stage to ‘input’—the form displays ok, but when I submit to the next template/page it displays “{embed=“main/survey_complete”}” rather than parsing it. If I put the embed outside of the rest of my PHP it works—inside (specifically after I make a query) it just displays the EE code rather than parsing it.

I’ve turned template debugging on, and it gives me no information of any use.

What am I doing wrong?

Profile
 
 
Posted: 28 August 2008 12:06 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRank
Total Posts:  1994
Joined  05-07-2007

OverDrive33:

I think you have template parsing order problems going on.  Is the “next template/page” the form action, do db stuff & display result page?  Can you post stripped down templates so the order can be seen?

Welcome to EE, you will like it.  smile

-greg

ps.  For forms/surveys, I HIGHLY recommend the Freeform Module by Solspace.

 Signature 
Profile
MSG
 
 
Posted: 28 August 2008 12:08 AM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  324
Joined  03-18-2007

Are you sure PHP is set to input on both templates, not just the first one?

Edit: And what Greg A. said!

Profile
 
 
Posted: 28 August 2008 09:13 AM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  5
Joined  08-27-2008

Okay. I’ve set all the templates to allow PHP and the parse order to input (just till I can get this sorted out).

Here’s the code for the survey page.

{embed="main/header_inc" survey="true"}
<form action="/index.php?/main/survey_complete/" method="POST">
<!--
Snip Input boxes, submit button  -->
</
form>
{embed="main/footer_inc"}

And here’s the ‘action’ survey_complete page.

<?PHP
if (isset($_REQUEST['action']))
    
$action = $_REQUEST['action'];
else
    
$action = "";
if (
$action == "surveyFilled"){
    
//Test for dupe emails    
    
$result = array();
    
/*Snip, standard PHP MySQL query stuff -- output to array: $result */    
    
if (count($result) > 0){
        ?>{embed
="main/header_inc"}<?PHP
        
echo "<h2>Whoops!</h2> That email has already been used in this survey. You may not enter twice.";
        
?>{embed="main/footer_inc"}<?PHP
        
die; //Halt the script here.
    
}

/*SNIP -- More PHP validation of inputs, attempt to INSERT into Mysql --*/

$mysqlError = mysql_error();
    if (
$mysqlError == ""){ // No errors, go ahead and display the thank you page
        
?>{embed="main/survey_thanks" survey="true"}<?PHP
    }else{
// There seems to have been a MySQL Error. Notify the user that there was a problem.
        
?>{embed="main/header_inc" survey="true"}<?PHP
        
echo "<!-- ".$mysqlError."-->";
        echo
"<h2>Whoops!</h2> There was an error processing your request. Please try again later.";
        
?>{embed="main/footer_inc"}<?PHP
    }
?>

The survey_complete page has it’s own (different) header and footer.

I originally had both on the same page, but in an attempt to correct my problem I made the survey_complete page a seperate template.

Edit—it works fine if it gets to embed the survey_thanks page, but if I try with a dupe email the output I get is:

{embed="main/header_inc"}<h2>Whoops!</h2> That email has already been used in this survey. You may not enter twice.{embed="main/footer_inc"}

I have one of those feelings that it’s something stupidly small I’m overlooking, and I’m going to look like a fool for having had to post to the support forms for this smile

Profile
 
 
Posted: 28 August 2008 10:03 AM   [ Ignore ]   [ # 4 ]  
Summer Student
Total Posts:  5
Joined  08-27-2008

Wait.

Does

<?PHP
die;
?>


Halt EE’s parsing too?


——*Edit*——

Yes it does. That was my whole problem.

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64912 Total Logged-in Users: 26
Total Topics: 81863 Total Anonymous Users: 18
Total Replies: 440100 Total Guests: 212
Total Posts: 521963    
Members ( View Memberlist )
Newest Members:  bjmohrAqua193Bios Elementmjpoteetguimogranwelshmrcfthenetmonkeybenekwhobutsb