# GenericForm

Yii required a form model to startup with. This could be an overhead if you just wanto ask for 2 input for example. GenericForm is here for this purpose.&#x20;

Its structure is basic and straightforward, support 5 variables, 1 file upload and 1 image upload. No rules and validation included, you will need to do that manually in your code.&#x20;

```php
<?php

class GenericForm extends CFormModel
{
	public $uploadPath;
	public $uploadFile_value;
	public $imageFile_value;
	public $var1;
	public $var2;
	public $var3;
	public $var4;
	public $var5;

	public function init()
	{
		$this->uploadPath = Yii::getPathOfAlias('uploads') . DIRECTORY_SEPARATOR . 'generic';
	}

	public function attributeLabels()
	{
		return array(
			'uploadFile_value' => Yii::t('core', 'Upload File'),
			'imageFile_value' => Yii::t('core', 'Image'),
			'var1' => Yii::t('core', 'Var 1'),
			'var2' => Yii::t('core', 'Var 2'),
			'var3' => Yii::t('core', 'Var 3'),
			'var4' => Yii::t('core', 'Var 4'),
			'var5' => Yii::t('core', 'Var 5'),
		);
	}
}

```

You can extend the form to set labels. This piece of code can either in a new model or simply at the bottom of your Controller where it is use. e.g.:

```php
class ReviewClaimForm extends GenericForm
{
	public function attributeLabels()
	{
		return array(
			'var1' => Yii::t('core', 'Organization / Team / Project'),
			'var2' => Yii::t('core', 'Note to applicant'),
			'var3' => Yii::t('core', 'Remark'),
		);
	}
}
```

Your controller would be something like:

```php
$submission = $backend->loadModel($id);
$model = new ReviewClaimForm;
$model->var1 = $submission->jsonArray_data->startup;
// var2: text_note
$model->var2 = $submission->jsonArray_extra->text_note;
// var3: remark
$model->var3 = $submission->jsonArray_extra->remark;

if (isset($_POST['ReviewClaimForm'])) {
    $submission->jsonArray_extra->text_note = $_POST['ReviewClaimForm']['var2'];
	$submission->jsonArray_extra->remark = $_POST['ReviewClaimForm']['var3'];
}
```

In view:

```php
<?php $form = $this->beginWidget('ActiveForm', array(
		'id' => 'review-form',
		// Please note: When you enable ajax validation, make sure the corresponding
		// controller action is handling ajax validation correctly.
		// There is a call to performAjaxValidation() commented in generated controller code.
		// See class documentation of CActiveForm for details on this.
		'enableAjaxValidation' => false,
		'htmlOptions' => array(
			'class' => 'crud-form',
			'role' => 'form',
			'enctype' => 'multipart/form-data',
		)
	)); ?>

		<div class="modal-body">

			<?php if ($model->hasErrors()): ?>
				<?php echo $form->bsErrorSummary($model); ?>
			<?php endif; ?>	
			
			<div class="form-group <?php echo $model->hasErrors('var1') ? 'has-error' : '' ?>">
				<?php echo $form->bsLabelFx0($model, 'var1'); ?>
				<div class="">
					<div class="form-control form-control-holder"><?php echo $model->var1 ?></div>
				</div>
            </div>
            
			<div class="form-group <?php echo $model->hasErrors('var2') ? 'has-error' : '' ?>">
				<?php echo $form->bsLabelFx0($model, 'var2'); ?>
				<div class="">
					<?php echo $form->bsHtmlEditor($model, 'var2', array('toolbar' => 'Mini', 'height' => '100px')); ?>
					<?php echo $form->bsError($model, 'var2'); ?>
				</div>
			</div>
            
			<div class="form-group <?php echo $model->hasErrors('var3') ? 'has-error' : '' ?>">
				<?php echo $form->bsLabelFx0($model, 'var3'); ?>
				<div class="">
					<?php echo $form->bsHtmlEditor($model, 'var3', array('toolbar' => 'Mini', 'height' => '100px')); ?>
					<?php echo $form->bsError($model, 'var3'); ?>
				</div>
			</div>
			
		</div>
		<div class="modal-footer">
			<?php echo $form->bsBtnSubmit(Yii::t('atas', 'Confirm Review')); ?>
			<?php echo Html::btnDefault(Yii::t('atas', 'Cancel'), $this->createUrl('claim/admin')); ?>
        </div>
        
        <?php $this->endWidget(); ?>
```

Another use case, on receiving file upload in Controller:

```php
$model = new GenericForm;
		$model->uploadFile_value = UploadedFile::getInstanceByName('file');
		if (is_object($model->uploadFile_value)) {
			$zip = new ZipArchive;
			$resource = $zip->open($model->uploadFile_value->tempName);
			if ($resource === true) {
				$zip->extractTo(Yii::getPathOfAlias('modules'));
				$zip->close();
			}
		}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://exiang.gitbook.io/yeebase/others/genericform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
