PRESTASHOP 1.6.3 で HelperForm クラスを使用する際に、date_add や date_upd などの非表示の値を追加したり、ユーザーに公開されていないフィールドに値を挿入したりする方法
新しいモジュールを作成しましたが、新しい追加が発生したときとユーザーが更新を行ったときに挿入する必要があるテーブルに 2 つのフィールドがありますが、PRESTASHOP で HelperForm クラスを使用しているときにこれを行う方法
以下は私のレンダリングフォームスクリプトです
// This form is populated when add or edit is clicked
public function renderForm()
{
$years = Tools::dateYears();
$months = Tools::dateMonths();
$days = Tools::dateDays();
$ticketSeries = Winners::getTicketSeries();
$prdtCategory = Winners::getProductCategory();
$nationality = Winners::getNationality();
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Configure your Winner'),
'icon' => 'icon-user'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'text',
'label' => $this->l('Ticket No'),
'name' => 'ticket_no',
'required' => true,
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
),
array(
'type' => 'select',
'label' => $this->l('Ticket Series'),
'name' => 'series',
'required' => true,
'options' => array(
'query' => $ticketSeries,
'id' => 'ticket_series_name',
'name' => 'ticket_series_name'
),
'col' => '4',
'hint' => array(
$this->l('The ticket series of each draw !!.')
)
),
array(
'type' => 'select',
'label' => $this->l('Category'),
'name' => 'category',
'required' => true,
'options' => array(
'query' => $prdtCategory,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Product Category.')
)
),
array(
'type' => 'date',
'label' => $this->l('Draw Date:'),
'name' => 'draw_date',
'size' => 10,
'required' => true,
'desc' => $this->l('The draw date of this series'),
),
array(
'type' => 'select',
'label' => $this->l('Nationality'),
'name' => 'nationality',
'required' => true,
'options' => array(
'query' => $nationality,
'id' => 'name',
'name' => 'name'
),
'col' => '4',
'hint' => array(
$this->l('Nationality the winner Belongs .')
)
),
array(
'type' => 'textarea',
'label' => $this->l('Testimonial'),
'name' => 'testimonial',
'required' => true,
'autoload_rte' => true,
'rows' => 7,
'cols' => 40,
'hint' => $this->l('Invalid characters:').' <>;=#{}'
), // add tag 'autoload_rte' => true, 'lang' => true, --> lang i removed
// since the editor value did not submit editor
)
);
//d(Tools::getIsset('update'));
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()@#"°{}_$%:'
))
));
$this->fields_form['submit'] = array(
'title' => $this->l('Save'),
);
$this->addJqueryUI('ui.datepicker');
return parent::renderForm();
}
以下のようなものを試しましたが、役に立ちません
if (Tools::getIsset('add') )
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Add Date'),
'name' => 'date_add',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"°{}_$%:'
))
));
if (Tools::getIsset('update'))
$this->fields_form = array_merge(array(
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Update Date'),
'name' => 'date_upd',
'col' => '4',
'hint' => $this->l('Invalid characters:').' 0-9!<>,;? =+()@#"°{}_$%:'
))
));