Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

form getDefaultParams is not working

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 08-13-2015, 05:40 AM
 
Roman Prisiazniuk Roman Prisiazniuk is offline
 

Member
  
Join Date: Jun 2015
Posts: 27
 

Default Handling forn

How can I add a form handler to my module that adds record in database? after adding record it must redirect to same page.
__________________
xcart5
Reply With Quote
  #2  
Old 08-15-2015, 08:27 AM
 
Roman Prisiazniuk Roman Prisiazniuk is offline
 

Member
  
Join Date: Jun 2015
Posts: 27
 

Default form getDefaultParams is not working

I have this model form:
PHP Code:
<?php
namespace XLite\Module\Romas\ProductActivation\View\Model;

class 
OrderItemActivation extends \XLite\View\Model\AModel{

    protected 
$schemaDefault = array(
        
'credit' => array(
            
self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            
self::SCHEMA_LABEL    => 'Credit',
            
self::SCHEMA_REQUIRED => true,
        ),
    );

    public function 
getModelId()
    {
        return 
false;
    }

    protected function 
getDefaultModelObject()
    {
        return new \
XLite\Module\Romas\ProductActivation\Model\OrderItemActivation;
    }

    protected function 
getFormClass()
    {
        return 
'\XLite\Module\Romas\ProductActivation\View\Form\Model\OrderItemActivation';
    }
}

PHP Code:
<?php

namespace XLite\Module\Romas\ProductActivation\View\Form\Model;

class 
OrderItemActivation extends \XLite\View\Form\AForm
{
    protected function 
getDefaultTarget()
    {
        return 
'add_activation';
    }

    protected function 
getDefaultAction()
    {
        return 
'update';
    }

    protected function 
getDefaultParams()
    {
        return array(
            
'date' => time(),
        );
    }
}

This code adds form to page with credit field and with hidden date field,
but when I submit form it does not insert date field to sql query, it just uses null, and I get this error
An exception occurred while executing 'INSERT INTO xc_order_item_activations (order_item_id, date, credit, activation_code, ip_address) VALUES (?, ?, ?, ?, ?)' with params [null, null, "2", null, null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'date' cannot be null
__________________
xcart5
Reply With Quote
  #3  
Old 08-15-2015, 08:32 AM
 
Roman Prisiazniuk Roman Prisiazniuk is offline
 

Member
  
Join Date: Jun 2015
Posts: 27
 

Default Re: form getDefaultParams is not working

Also tell me please next:
I added multiple forms(as above) on my order page, every order item has its own form, how can I add hidden field to this form that must have valu of order_item_id?
__________________
xcart5
Reply With Quote
  #4  
Old 08-18-2015, 11:42 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: form getDefaultParams is not working

Quote:
Originally Posted by Roman Prisiazniuk
when I submit form it does not insert date field to sql query, it just uses null, and I get this error
An exception occurred while executing 'INSERT INTO xc_order_item_activations (order_item_id, date, credit, activation_code, ip_address) VALUES (?, ?, ?, ?, ?)' with params [null, null, "2", null, null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'date' cannot be null

This is because your $schemaDefault describes the "credit" field only, so X-Cart uses "null" value for the rest of the entity fields.

You may try to set the missing properties in the View\Model\OrderItemActivation ::setModelProperties() method.


Quote:
Originally Posted by Roman Prisiazniuk
Also tell me please next:
I added multiple forms(as above) on my order page, every order item has its own form, how can I add hidden field to this form that must have valu of order_item_id?


You can add hidden fields to a form by declaring them in the getDefaultParams() method of your form class that extends \XLite\View\Form\AForm.

For example, check the \XLite\View\Form\Profile class.
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 03:47 AM.

   

 
X-Cart forums © 2001-2020