Page 1 of 1

little help for a php noob

Posted: Fri Jul 09, 2010 1:48 pm
by johnnyblotter
Hi folks.

I am doing a very simple php require statement to include the header on every page of the site.

Code: Select all

<?php require("includes/main-navigation.php"); ?>
The problem is with a form validation script. The validation script originally was set to embed either "error.htm" or "success.htm" into the page. Since I want the error page and success pages to display like other pages, I added the require statement to the these pages, and saved them as error.php and success.php. What happens is the page that's served won't output the php, and just shows the php statement in the source code.

The form validation is long but here's the relevant bit:

Code: Select all

// Embed error page and dump it to the browser

$fileErrorPage = 'error.php';

if ( $validationFailed == true) {
    if ( file_exists( $fileErrorPage) === false) {
        echo 'The error page: <b>' . $fileErrorPage . '</b> cannot be found on the server.';
        exit;
    }

    $fileHandle = fopen ( $fileErrorPage, 'r');
    $errorPage = fread ( $fileHandle, filesize( $fileErrorPage));
    fclose ( $fileHandle);

    $errorPage = str_replace( '<!--VALIDATIONERROR-->', $errorList, $errorPage);
    echo $errorPage;
    exit;
}

// END ERROR VALIDATION SECTION

$fileSuccessPage = 'success.php';

if ( file_exists( $fileSuccessPage) === false) {
    echo 'The success page: <b> ' . $fileSuccessPage . '</b> cannot be found on the server.';
    exit;
}

$fileHandle = fopen ( $fileSuccessPage, "r");
$successPage = fread ( $fileHandle, filesize( $fileSuccessPage));
fclose ( $fileHandle);

echo $successPage;

exit;

Any idea why the page that's served wouldn't be able to output the php? Thanks....

Re: little help for a php noob

Posted: Fri Jul 09, 2010 2:03 pm
by Jade
Why are you reading in the page with fopen? Either include it or redirect to it.

Code: Select all

// Embed error page and dump it to the browser

$fileErrorPage = 'error.php';

if ( $validationFailed == true) {
    if ( file_exists( $fileErrorPage) === false) {
        echo 'The error page: <b>' . $fileErrorPage . '</b> cannot be found on the server.';
        exit;
    }

    //redirect to the error page
    header("Location: " . $fileErrorPage);

     //or include the error page
    include($fileErrorPage);
    exit;
}

Re: little help for a php noob

Posted: Fri Jul 09, 2010 6:27 pm
by johnnyblotter
hmmm. That allows the correct file to display and output the php, but I lose all my validation errors...

Code: Select all

$errorPage = str_replace( '<!--VALIDATIONERROR-->', $errorList,  $errorPage);
    echo $errorPage;
    exit;
On the error.php page, <!--VALIDATIONERROR--> is not replaced with the errors as it should be....

I know I'm a noob! Can anyone help me sort this out? Thanks...

Re: little help for a php noob

Posted: Mon Jul 12, 2010 9:17 am
by Jade
Change your error page so that it uses <?php echo $VALIDATORERROR; ?> and then you can set $VALIDATORERROR prior to including the $errorPage. That way when the error page is displayed the $VALIDATORERROR is within the scope and it'll display whatever you want it to.