waxman
Total posts: 1
01 Apr 2018 20:21

I've got a simple code below. After it's run once, it inserts results twice into the mysql database. components/com_cobalt/fields/text/text.php

    public function onPrepareSave($value, $record, $type, $section)
    {

            // START my custom code
            $db = JFactory::getDbo();
            // Create a new query object.
            $query = $db->getQuery(true);

            $query = "INSERT INTO #__moje1 (cat, sub)
            VALUES ('1', $value)";

            // Set the query using our newly populated query object and execute it.
            $db->setQuery($query);
            $db->execute();
                // END my custom code    

        if($this->params->get('params.mask.mask') && $this->params->get('params.show_mask', 1) && ($value == $this->params->get('params.mask.mask')))
        {
            return null;
        }

        $filter = JFilterInput::getInstance();
        return $filter->clean($value);
    }

https://image.ibb.co/gRj4H7/create_topic.png

https://image.ibb.co/hNDQPn/mysql.png

Last Modified: 04 Apr 2018


Sergey
Total posts: 13,748
04 Apr 2018 11:41

This is because onPrepareSave is called twice. It i sonly to prepare value to store. Use onStoreValue to run your query.

Powered by Cobalt