Jump to content

How to save text from textarea?


Xymor
 Share

Recommended Posts

Hi, I cant save value of textarea

 

public function getContent()
{
if (Tools::isSubmit('submitSomeModule'))
{
Configuration::updateValue('some_text', Tools::getValue('some_text'), true);
}
return $this->renderForm();
}
 
protected function renderForm()
array(
'type' => 'textarea',
'label' => $this->l('Text field content'),
'name' => 'some_text',
'lang' => true,
'autoload_rte' => true,
'cols' => 60,
'rows' => 30, 
),
$helper->tpl_vars = array(
'fields_value' => $this->getConfigFieldsValues(), /* Add values for your inputs */
'languages' => $this->context->controller->getLanguages(),
'id_language' => $this->context->language->id,
);
 
 
public function getConfigFieldsValues()
{
 
return array(
'some_text' => Tools::getValue('some_text', Configuration::get('some_text')),
);
}
 
protected function postProcess()
{
$form_values = $this->getConfigFieldsValues();
foreach (array_keys($form_values) as $key)
Configuration::updateValue($key, Tools::getValue($key));
}

 

Share this post


Link to post
Share on other sites

  • 2 months later...

How did you solved the problem?

Problem solved isn't a very friendly/helpful answer. :(

 

EDIT:

 

Fortunately I could find the problem and here is the explanation for my case (it could be the case for someone else in the future).

 

I will take the code above as example. So, in the code above, there is this:

Configuration::updateValue('some_text', Tools::getValue('some_text'), true);

And in my case, my code was looking like this:

Configuration::updateValue('some_text', (float)Tools::getValue('some_text'), true);

So there's (float) which is "Floating point numbers" (for those who want to know more about it go here: http://php.net/manual/en/language.types.float.php ) and that's what was only accepting numbers as input, not allowing me to save text. :)

Edited by plima (see edit history)

Share this post


Link to post
Share on other sites

I don't recall where i had an error but i can post how my code looks now (it won't work with prestashop below 1.6)

   public function getContent()
    {
        if (Tools::isSubmit('submitSOME_MODULE'))
        {
        ...
        Configuration::updateValue('SOME_MODULE_TEXT_FIELD', Tools::getValue('SOME_MODULE_TEXT_FIELD'), true);
        ...
        }
        return $this->renderForm();
    }

in protected function renderForm() :

array(
                        'type' => 'textarea',
                        'label' => $this->l('Text field content'),
                        'name' => 'SOME_MODULE_TEXT_FIELD',                       
 'desc' => $this->l('Text field content.'),
                        'autoload_rte' => true,
                        'cols' => 50,
                        'rows' => 20,
                    ),

next:

	public function getConfigFieldsValues()
	{
		return array(
			....
			'SOMEMODULE_TEXT_FIELD' => Tools::getValue('SOMEMODULE__TEXT_FIELD', Configuration::get('SOMEMODULE__TEXT_FIELD'))
		);
	}
protected function postProcess()
	{
		$form_values = $this->getConfigFieldsValues();
		foreach (array_keys($form_values) as $key)
			Configuration::updateValue($key, Tools::getValue($key));
	}
Edited by Xymor (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More