HOW TO create form with CDataForm widget?

Discuss everything related to ApPHP Durecty CMF. All versions. Any questions related to the Directy CMF developing or using should be posted to this forum.

Moderators: alexandrleonenko, alexmst

administrator
Site Admin
Site Admin
Posts: 6169
Joined: Jan 7th, '09, 23:18
Contact:

HOW TO create form with CDataForm widget?

Postby administrator » Sep 2nd, '14, 19:10

Working with DataForm is a simple process.
You have to define it in a following way (look in framework/helpers/widgets/CDataForm.php for more info):

Code: Select all

echo CWidget::create('CDataForm', array(
    'model'=>'tableName',
    'primaryKey'=>1,
    'operationType'=>'', /* add or edit */
    'action'=>'', /* locations/add or locations/edit/id/1 */
    'successUrl'=>'', /* locations/manage/msg/1 or locations/manage/id/{id} */
    'successCallback'=>array('add'=>'', 'edit'=>''),  /* methods must be public methods of controller */
    'cancelUrl'=>'', /* ex.: locations/manage */
    'passParameters'=>false,
    'method'=>'post',
    'htmlOptions'=>array(
        'name'=>'form-contact',
        'enctype'=>'multipart/form-data',
        'autoGenerateId'=>true
    ),
    'requiredFieldsAlert'=>true,
    'fieldSetType'=>'frameset|tabs',
    'fields'=>array(),
    'translationInfo'=>array(),
    'translationFields'=>array(),
    'buttons'=>array(),
    'buttonsPosition'=>'bottom',
    'messagesSource'=>'core',
    'showAllErrors'=>false,
    'return'=>true,
))


Here the full example for table Countries:

Code: Select all

echo CWidget::create('CDataForm', array(
    'model'=>'Countries',
    'primaryKey'=>$country->id,
    'operationType'=>'edit',
    'action'=>'locations/edit/id/'.$country->id,
    'successUrl'=>'locations/manage/msg/updated',
    'cancelUrl'=>'locations/manage',
    'passParameters'=>true,
    'requiredFieldsAlert'=>true,
    'return'=>true,
    'htmlOptions'=>array(
        'name'=>'frmLocationEdit',
        'enctype'=>'multipart/form-data',
        'autoGenerateId'=>true
    ),
    'fields'=>array(
        'code'       => array('type'=>'label', 'title'=>A::t('app', 'Code'), 'tooltip'=>''),
        'is_active'  => array('type'=>'checkbox', 'title'=>A::t('app', 'Active'), 'htmlOptions'=>($country->is_default == 1 ? array('disabled'=>'disabled', 'uncheckValue'=>$country->is_active) : array())),
        'is_default' => array('type'=>'checkbox', 'title'=>A::t('app', 'Default'), 'htmlOptions'=>($country->is_default == 1 ? array('disabled'=>'disabled', 'uncheckValue'=>$country->is_default) : array())),                   
        'sort_order' => array('type'=>'textbox', 'title'=>A::t('app', 'Sort Order'), 'tooltip'=>'', 'validation'=>array('required'=>true, 'maxLength'=>'4', 'type'=>'numeric'), 'htmlOptions'=>array('maxLength'=>'4', 'class'=>'small')),
    ),
    'translationInfo' => array('relation'=>array('code', 'country_code'), 'languages'=>Languages::model()->findAll('is_active = 1')),
    'translationFields' => array(
        'name' => array('type'=>'textbox', 'title'=>A::t('app', 'Name'), 'tooltip'=>'', 'validation'=>array('required'=>true, 'type'=>'any'), 'htmlOptions'=>array('title'=>'')),
    ),
    'buttons' => array(
        'submitUpdateClose' => array('type'=>'submit', 'value'=>A::t('app', 'Update & Close'), 'htmlOptions'=>array('name'=>'btnUpdateClose')),
        'submitUpdate' => array('type'=>'submit', 'value'=>A::t('app', 'Update'), 'htmlOptions'=>array('name'=>'btnUpdate')),
        'cancel' => array('type'=>'button', 'value'=>A::t('app', 'Cancel'), 'htmlOptions'=>array('name'=>'', 'class'=>'button white')),
    ),               
));


cdataform.png
cdataform.png (28.37 KiB) Viewed 2588 times

Return to “ApPHP Directy CMF {developers/users}”