PHP code example of freesoftwarefactory / smartform

1. Go to this page and download the library: Download freesoftwarefactory/smartform library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

freesoftwarefactory / smartform example snippets


[php]

	use yii\widgets\ActiveForm;
	
    $form = ActiveForm::begin();
	echo \app\components\SmartformWidget::widget([
		'config_entry'=>'field-groups',
		'form_id'=>'form-1',
		'active_form'=>$form,
		'model'=>$model,
	]);
	ActiveForm::end();

[php]

	
	function _somecallback($_call,$_model,$_field_name){
		if('select-options' == $_call){
			if('some_custom_field_name'==$_field_name){
				$options = [''=>'--Choose--'];
				foreach(\app\models\Options::all() as $item)
					$options[$item->id] = $item->text;
				return $options;
			}
		}
	}
	

		echo \app\components\SmartformWidget::widget([
			'config_entry'=>'field-groups',
			'form_id'=>'some-form-id',
			'active_form'=>$form,
			'model'=>$model,
			'callback' => function($_call,$_model,$_fieldname){
				
				if('get_file_upload_url'==$_call){
					return \yii\helpers\Url::toRoute(['ajax-upload-product-image']);
				}

				if('instance_files' == $_call){
					$list = [];
					if('product_image'==$_fieldname) $list[] = [
						'id'=>1, 'file_name'=>'', 'file_path'=>'',
						'preview_url'=>'/media/landingpage/product/thumb/'.$_model->id,
						'delete_url'=>'',
					];
					return $list;
				}
			}
		]);

	// methods nction beforeAction($action) {            
		if($action->id == 'ajax-upload-product-image') 
			$this->enableCsrfValidation = false;
		return parent::beforeAction($action);
	}
	
	public function actionAjaxUploadProductImage(){
		if(!Yii::$app->request->isAjax) die('invalid ajax request');
		\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
		
		$model_id=filter_input(INPUT_POST,"model_id",FILTER_SANITIZE_STRING);
		
		// this will help you to get more information:
		Yii::info("UPLOAD_INFO\n", print_r(["POST"=>$_POST,"FILES"=>$_FILES],true));
		
		$model = $this->findModel($model_id);
		$tmp_file = $_FILES['Landingpage']['tmp_name']['product_image'];	
		$binary_data = file_get_contents($tmp_file);
		
		return [];
	}