PHP code example of demogorgorn / yii2-ajax-submit-button
1. Go to this page and download the library: Download demogorgorn/yii2-ajax-submit-button 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/ */
demogorgorn / yii2-ajax-submit-button example snippets
use demogorgorn\ajax\AjaxSubmitButton;
echo Html::beginForm('', 'post', ['class'=>'uk-width-medium-1-1 uk-form uk-form-horizontal']);
public function actionGetinfo()
{
if(!isset($_POST['country_code']) || empty($_POST['country_code']))
return;
$code = $_POST['country_code'];
return $this->renderAjax('resultwidget', ['code' => $code]);
}
AjaxSubmitButton::begin([
'label' => 'Сохранить',
'useWithActiveForm' => 'add-form',
'ajaxOptions' => [
'type' => 'POST',
'processData' => false, // Don't process the files
'contentType' => false, // Set content type to false as jQuery will tell the server its a query string request
'data' => new \yii\web\JsExpression("new FormData($('#add-form')[0])"), // Do not stringify the form
'success' => new \yii\web\JsExpression("function(data) {
if (data.status == true)
{
// process result
}
}"),
],
'options' => ['class' => 'btn btn-primary', 'type' => 'submit', 'id' =>'add-button'],
]);
AjaxSubmitButton::end();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.