0
votes

I couldn't come up with a better title for my question, so I will do the best I can to describe the problem.

I DO NOT WANT TO SPEW TEXT HERE, but it may be the only way to get my point across. If you want to see a live demonstration of the issue, go to: www.dopeoplestillplay.com -> view source -> submit the form -> view source again.

I have a website running Codeigniter as my MVC framework. The home page is extremely basic and consists of the following components:

Welcome.php Controller:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {
    public function index()
    {       
        $page = 'home';
        if ( ! file_exists(APPPATH.'/views/statics/'.$page.'.php')) {
            show_404();
        }

        $data['title'] = ucfirst($page); // Capitalize the first letter
        $data['css'] = 'statics/'.$page.'.css';

        $this->load->view('templates/header', $data);
        $this->load->view('statics/'.$page, $data);
        $this->load->view('templates/footer', $data);
    }
}

The header template:

<!DOCTYPE html>
<html>
        <head>
            <?php
                $this->load->helper('html');
                include_once('resources/Strings.php'); 
            $rsString = new ResourceStrings();

                // Echo all of the meta tags needed by the page, get the data from the controller. 
                $meta = array(
                    array('name' => 'robots', 'content' => 'no-cache'),
                    array('name' => 'description', 'content' => $rsString::$metaStrings['DESCRIPTION']),
                    array('name' => 'keywords', 'content' => $rsString::$metaStrings['KEYWORDS']),
                    array('name' => 'robots', 'content' => 'no-cache'),
                    array('name' => 'Content-type', 'content' => 'text/html; charset=utf-8', 'type' => 'equiv')
            );

            echo meta($meta); 
            ?>
                <title><?php if(!is_null($title)){echo $title;} ?> - Do People Still Play..?</title>

                <?php
                    // Echo the CSS tags that are used for the reset, normalization, framework, and master styles. 
                    echo link_tag('css/reset.css');
                    echo link_tag('css/normalize.css');
                    echo link_tag('css/libs/skeleton.css');
            echo link_tag('css/master.css');

            // Echo page specific tags here
            if(isset($css)){
                echo link_tag('css/'.$css);
            }

            // Echo the jQuery Hosted library tags
            echo '<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>'
                ?>
        </head>
        <body>
        <div class="container">

The main content (home.php):

<?
    include_once('resources/Strings.php'); 
    $rsString = new ResourceStrings();
?>
<section class="header">
    <h2 class="title">Do People Still Play..?</h2>
    <h5 class="title">We are currently under construction! Find out if people are still playing your favorite games, after we launch!</h5>
</section>

<form name="user-email-info" class="construction-email" action="/forms/handle/construct-email" method="post">
    <div class="row">
        <div class="one-third columns">
            <p class="flavor-text"><?php echo $rsString::$homeStrings['CONSTRUCTION_TEXT'];?></p>
            <input class="email-input" name="user-email" type="email" placeholder="[email protected]">
            <?php echo br(1); ?>
            <input class="button-primary email-button" type="submit" value="construct-email">
        </div>
    </div>
</form>

And finally, the footer:

        <div class="row">
                <div class="three columns">&nbsp;</div>
                <em class="six columns footer-text">Created By: Brendan Lesniak &copy; <?php echo date("F d Y H:i:s", getlastmod()); ?></em>
                <div class="three columns">&nbsp;</div>
            </div>
        </div>
        </body>
</html>

The home page produces the desired HTML format and results:

<html>
    <head>
        [SNIP TAGS]
    </head>
    <body>
        [SNIP CONTENT]
    </body>
</html>

Ok, after submitting the form, it is handled with the following method:

private function handleEmailRequest($requestParams) {
    // Since this is an email, the requestParams will be an email address
    $email = $requestParams;
    // Required page data, either leave blank or add specific entries here
    $data['title'] = 'Email Submission';

    // Load the templates, and echo the data we got in the middle. 
    $this->load->view('templates/header', $data);
    echo $email;
    $this->load->view('templates/footer', $data);
}

When returning from the FormController, I get the following HTML format, where suddenly, all the meta/css/script tags are moved to the body of the page:

<html>
    <head>
    </head>
    <body>
        [SNIP TAGS]
        [SNIP CONTENT]
    </body>
</html>

It must be a problem in the way I am handling the form submission, but I really don't know what I could be missing. Again, I wish there was a better way to illustrate my issue, as I did not want to have a wall of code/text.

1
Ok. I posted this and then found the issue. The echo $email in the emailHandler causes the page to be treated as the body. - Brendan Lesniak

1 Answers

0
votes

When I was handling the email request with:

private function handleEmailRequest($requestParams) {
    // Since this is an email, the requestParams will be an email address
    $email = $requestParams;
    // Required page data, either leave blank or add specific entries here
    $data['title'] = 'Email Submission';

    // Load the templates, and echo the data we got in the middle. 
    $this->load->view('templates/header', $data);
    echo $email;
    $this->load->view('templates/footer', $data);
}

the echo $email; statement caused the page to be interpreted as the body of the page. Instead I am now using a proper view to show the data that was submitted:

private function handleEmailRequest($requestParams) {
    // Since this is an email, the requestParams will be an email address
    $email = $requestParams;
    // Required page data, either leave blank or add specific entries here
    $data['title'] = 'Email Submission';

    // Load the templates, and echo the data we got in the middle. 
    $this->load->view('templates/header', $data);
    $this->load->view('statics/email_confirmation', $data);
    $this->load->view('templates/footer', $data);
}