Jump to content

Save html in textarea


Recommended Posts

I create module with input text and textarea and I have problem - my html tags are not save in my database.

How to solve it?

 

Now after update my html tags are omitted,

 

That's my code:

<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class Wysuwany_panel extends Module
{
  public function __construct()
  {
    $this->name = 'wysuwany_panel';
    $this->tab = 'front_office_features';
    $this->version = '1.0.0';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 
    $this->bootstrap = true;
 
    parent::__construct();
 
    $this->displayName = $this->l('Wysuwany panel');
    $this->description = $this->l('Modul dodajacy wysuwany panel do Prestashop');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('MYMODULE_NAME'))      
      $this->warning = $this->l('No name provided');
  }
  public function install()
  {
		if (parent::install() == false || $this->registerHook('displayHeader') == false || $this->registerHook('displayFooter') == false 
									   || Configuration::updateValue('DB_title_of_panel', 'Wysuwany panel') == false
									   || Configuration::updateValue('DB_content_of_panel', 'Przykladowa tresc') == false )
				return false;
		return true;
  }
  public function hookdisplayHeader($params)
  {
		$this->context->controller->addCSS(($this->_path).'wysuwanypanel.css', 'all');
  }
  public function hookDisplayFooter($params)
  {
	  $titleOfPanel = Configuration::get("DB_title_of_panel");
	  $contentOfPanel = Configuration::get("DB_content_of_panel");
	  $this->smarty->assign(array(
            'titleOfPanel' => $titleOfPanel,
			'contentOfPanel' => $contentOfPanel
      ));
	 return $this->display(__FILE__, 'wysuwanypanel.tpl');
  }
  public function getContent()
  {
    $output = null;
 
    if (Tools::isSubmit('submit'.$this->name))
    {
        $titleOfPanel = strval(Tools::getValue('DB_title_of_panel'));
		$contentOfPanel = Tools::getValue('DB_content_of_panel');
        if (!$titleOfPanel
          || empty($titleOfPanel)
          || !Validate::isGenericName($titleOfPanel))
            $output .= $this->displayError($this->l('Invalid Configuration value'));
        else
        {
            Configuration::updateValue('DB_title_of_panel', $titleOfPanel);
			Configuration::updateValue('DB_content_of_panel', $contentOfPanel);
            $output .= $this->displayConfirmation($this->l('Settings updated'));
        }
    }
    return $output.$this->displayForm();
  }
  public function displayForm()
  {
    // Get default language
    $default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
     
    // Init Fields form array
    $fields_form[0]['form'] = array(
        'legend' => array(
            'title' => $this->l('Settings'),
        ),
        'input' => array(
            array(
                'type' => 'text',
                'label' => $this->l('Tytul wysuwanego paska'),
                'name' => 'DB_title_of_panel',
                'size' => 20,
                'required' => true
            ),
			array(
                            'type' => 'textarea',
                            'label' => $this->l('Tresc wysuwanego paska'),
                            'name' => 'DB_content_of_panel',
							'class' => 'rte',
							'autoload_rte' => true
            )
        ),
        'submit' => array(
            'title' => $this->l('Save'),
            'class' => 'btn btn-default pull-right'
        )
    );
     
    $helper = new HelperForm();
     
    // Module, token and currentIndex
    $helper->module = $this;
    $helper->name_controller = $this->name;
    $helper->token = Tools::getAdminTokenLite('AdminModules');
    $helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;
     
    // Language
    $helper->default_form_language = $default_lang;
    $helper->allow_employee_form_lang = $default_lang;
     
    // Title and toolbar
    $helper->title = $this->displayName;
    $helper->show_toolbar = true;        // false -> remove toolbar
    $helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
    $helper->submit_action = 'submit'.$this->name;
    $helper->toolbar_btn = array(
        'save' =>
        array(
            'desc' => $this->l('Save'),
            'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
            '&token='.Tools::getAdminTokenLite('AdminModules'),
        ),
        'back' => array(
            'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
            'desc' => $this->l('Back to list')
        )
    );
     
    // Load current value
    $helper->fields_value['DB_title_of_panel'] = Configuration::get('DB_title_of_panel');
	$helper->fields_value['DB_content_of_panel'] = Configuration::get('DB_content_of_panel');
     
    return $helper->generateForm($fields_form);
   }
  
  
}
Link to comment
Share on other sites

hello,

please take a look on this function:

Configuration::updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null)

 

third variable is $html, by default its value is FALSE

 /**
 * @param bool $html Specify if html is authorized in value
 */

so, to update value in db with html use third param in Configuration::updateValue with value TRUE - function will save variable in db with html then :-)

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...