IeM
IeM

Reputation: 61

Prestashop, How to Create a New Non-CMS Page For JS,CSS, PHP

Prestashop V1.6

Hi,

I need to create a new non-cms Form Page that includes some logic, JS, CSS, and maybe PHP.

This page will submit to a PHP script that will perform some logic and redirect back to this page.

If possible it would be good to include PHP in this Form Page, but if not, I will need to include PHP in a FormPageController and use a template file or something.

Apart from the body, that will include the form, the page needs to look like the shop so it will need to include the Header and Footer.

I tried using a CMS page but it was too restrictive in what it was allow.

I also set up a root file: form-page.php

<?php
  include(dirname(__FILE__).'/config/config.inc.php');
  Tools::displayFileAsDeprecated();
  include(dirname(__FILE__).'/header.php');
  $smarty->display(_PS_THEME_DIR_.'form-page.tpl');
  include(dirname(__FILE__).'/footer.php');

A controller: FormPage.php

<?php
class FormPageControllerCore extends FrontController
{
    public function init(){
      parent::init();
    }
    public function setMedia()
    {
        parent::setMedia();
        $this->addCSS(_THEME_CSS_DIR_.'form-page.css');
        $this->addJS(_THEME_JS_DIR_.'form-page.js');
        $this->addJS(_PS_JS_DIR_.'validate.js');
    }

    public function initContent()
    {
        parent::initContent();
    }
}
?>

A template file: form-page.tpl

<div>
  <!-- HTML -->
</div>
{literal}
  <style type="text/css">
  </style>
{/literal}

<script type="text/javascript">
  {literal}
  {/literal}
</script>

And linked the page in the Admin->Preferences->SEO Pages

As a result I was only getting back totally black pages.

To complete this task, are there any other files I have to add?

What is the minimum skeleton for each of the required files to make this work?

Where else may I be going wrong?

Thanks

Upvotes: 0

Views: 641

Answers (1)

elPresta
elPresta

Reputation: 648

1) Create a php file in PS root: formpage.php (for example)

include(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
include(dirname(__FILE__).'/header.php');
$smarty->display(_PS_THEME_DIR_.'formpage.tpl');
include(dirname(__FILE__).'/footer.php');

2) Create a new controller: root/controllers/front/FormpageController.php

class FormpageController extends FrontController{

    public function init(){
        parent::init();
    }

        public function setMedia()
    {
        parent::setMedia();   
        $this->addJS(_THEME_JS_DIR_.'formpage.js');  
    }


    public function initContent(){
    parent::initContent();
    $this->setTemplate(_PS_THEME_DIR_.'formpage.tpl');
    }
}

3) Create a new .tpl file in your theme folder Your content

So in your example I think your controller file name bad?

After all delete cache-> class_index.php file

Upvotes: 1

Related Questions