X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   General questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=66)
-   -   Dealing wiht Form in X-Cart 5 (https://forum.x-cart.com/showthread.php?t=76215)

Soptareanu @Alex 05-03-2018 02:48 AM

Dealing wiht Form in X-Cart 5
 
Hello, I create a form. This is my class that define my form widget :
<?php

namespace XLite\Module\Fdmteam\Xretur\View\Model ;

class ReturForm extends \XLite\View\Model\AModel
{
/**
* @inheritdoc
*/
public function __construct($params = [], $sections = [])
{
$this->schemaDefault = [
'name' => [
self::SCHEMA_CLASS => '\XLite\View\FormField\Input\Text',
self::SCHEMA_LABEL => static::t('Name'),
self::SCHEMA_PLACEHOLDER => static::t('Name'),
self::SCHEMA_REQUIRED => true,
],
'email' => [
self::SCHEMA_CLASS => '\XLite\View\FormField\Input\Text\Email',
self::SCHEMA_LABEL => static::t('Email'),
self::SCHEMA_PLACEHOLDER => static::t('Email'),
self::SCHEMA_REQUIRED => true,
],
'phone' => [
self::SCHEMA_CLASS => '\XLite\View\FormField\Input\Text\Phone',
self::SCHEMA_LABEL => static::t('Phone'),
self::SCHEMA_PLACEHOLDER => static::t('Phone'),
self::SCHEMA_REQUIRED => true,
],
'invoice_number' => [
self::SCHEMA_CLASS => '\XLite\View\FormField\Input\Text\Integer',
self::SCHEMA_LABEL => static::t('Invoice'),
self::SCHEMA_PLACEHOLDER => static::t('Invoice Number'),
self::SCHEMA_REQUIRED => true,
],
'reason' => [
self::SCHEMA_CLASS => '\XLite\Module\Fdmteam\Xretur\View\FormField\Selec t\Reasons',
self::SCHEMA_LABEL => static::t('Reason'),
self::SCHEMA_PLACEHOLDER => static::t('Reason'),
self::SCHEMA_REQUIRED => true,
\XLite\View\FormField\AFormField::FIELD_TYPE_SELEC T => true,
],
'desire' => [
self::SCHEMA_CLASS => '\XLite\Module\Fdmteam\Xretur\View\FormField\Selec t\Desireds',
self::SCHEMA_LABEL => static::t('Desired'),
self::SCHEMA_PLACEHOLDER => static::t('Desired'),
self::SCHEMA_REQUIRED => true,
\XLite\View\FormField\AFormField::FIELD_TYPE_SELEC T => true,
],
'date' => [
self::SCHEMA_CLASS => '\XLite\Module\Fdmteam\Xretur\View\FormField\Input \Text\DatePicker',
self::SCHEMA_LABEL => static::t('Date'),
self::SCHEMA_REQUIRED => true,
self::SCHEMA_PLACEHOLDER => static::t('Date'),
\XLite\View\FormField\AFormField::PARAM_FIELD_ONLY => false,
],
'message' => [
self::SCHEMA_CLASS => '\XLite\View\FormField\Textarea\Simple',
self::SCHEMA_LABEL => static::t('Message'),
self::SCHEMA_PLACEHOLDER => static::t('Message'),
self::SCHEMA_REQUIRED => true,
\XLite\View\FormField\Textarea\ATextarea::PARAM_RO WS => 5,
\XLite\View\FormField\Textarea\ATextarea::PARAM_CO LS => 21
],
'table' => [
self::SCHEMA_CLASS => '\XLite\Module\Fdmteam\Xretur\View\FormField\Table \CustomTable',
self::SCHEMA_LABEL => static::t('Table'),
self::SCHEMA_PLACEHOLDER => static::t('Aici trebuie sa pun tabelul'),
self::SCHEMA_REQUIRED => true,
\XLite\View\FormField\AFormField::PARAM_FIELD_ONLY => false,
],
];

parent::__construct($params, $sections);
}

public function getModelId()
{
return \XLite\Core\Request::getInstance()->id;
}

protected function getDefaultModelObject()
{
$model = $this->getModelId()
? \XLite\Core\Database::getRepo('XLite\Module\Fdmtea m\Xretur\Model\FormRetur')->find($this->getModelId())
: null;

return $model ?: new \XLite\Module\Fdmteam\Xretur\Model\FormRetur ;
}

protected function getFormClass()
{
return '\XLite\Module\Fdmteam\Xretur\View\Form\Model\Retu rForm';
}

/**
* Return list of the "Button" widgets
*
* @return array
*/
protected function getFormButtons()
{
$result = parent::getFormButtons();

$result['submit'] = new \XLite\View\Button\Submit(
[
\XLite\View\Button\AButton::PARAM_LABEL => static::t('Send Form'),
\XLite\View\Button\AButton::PARAM_BTN_TYPE => 'btn regular-main-button submit'
]
);

return $result;
}
}

Is there a way to split this form in two separated columns when i render the widget in my view without apply any particular css styles or something, only using x-cart configs ?!
This is my view
<div class="form-wrapper">
{{ widget('\\XLite\\Module\\Fdmteam\\Xretur\\View\\Mo del\\ReturForm') }}
</div>

qualiteam 05-06-2018 11:53 PM

Re: Dealing wiht Form in X-Cart 5
 
There is no built-in way to display the form in two columns, however you can split it into two "sections" and make it appear as two columns with CSS.

Here is an example from the PayPal module:
PHP Code:

namespace XLite\Module\CDev\Paypal\View\Model;

abstract class 
ASettings extends \XLite\View\Model\AModel
{
    
/**
     * Form sections
     */
    
const SECTION_ACCOUNT    'account';
    const 
SECTION_ADDITIONAL 'additional';

    protected 
$schemaAccount = array(
        
// ...
        
'user' => array(
            
self::SCHEMA_CLASS    => 'XLite\View\FormField\Input\Text',
            
self::SCHEMA_LABEL    => 'User',
            
self::SCHEMA_HELP     => 'PayPal recommends entering a User Login here instead of your Merchant Login',
            
self::SCHEMA_REQUIRED => true,
        ),
        
// ...
    
);

    protected 
$schemaAdditional = array(
        
// ...
        
'mode' => array(
            
self::SCHEMA_CLASS    => 'XLite\View\FormField\Select\TestLiveMode',
            
self::SCHEMA_LABEL    => 'Test/Live mode',
            
self::SCHEMA_REQUIRED => false,
        ),
        
// ...
    
);

    
// ...

    
public function __construct(array $params = array(), array $sections = array())
    {
        
$this->sections $this->getSettingsSections() + $this->sections;
        
parent::__construct($params$sections);
    }

    protected function 
getSettingsSections()
    {
        return array(
            static::
SECTION_ACCOUNT    => 'Your account settings',
            static::
SECTION_ADDITIONAL => 'Additional settings',
        );
    }

    
// ...





All times are GMT -8. The time now is 09:05 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.