siripravi/yii2-modal

Modal widget for Yii2

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 1

Type:yii2-extension

v1.0 2024-11-06 09:41 UTC

This package is auto-updated.

Last update: 2024-12-06 15:06:29 UTC


README

Modal widget for Yii2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist siripravi/yii2-modal "*"

or add

"siripravi/yii2-modal": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

<button data-modal="/site/modal-test" data-modal-size="modal-sm">Open Modal</button>

<button onclick="openModal('/site/modal-test', { size: 'modal-lg' });">Open Modal</button>

<button onclick="openModal(null, { title: 'Title', body: 'Body' });">Open Modal</button>

<?= \siripravi\modal\Modal::widget(); ?>
public function actionModalTest()
{
    $footer = Html::button('Close', ['class' => 'btn btn-secondary', 'data-dismiss' => 'modal']);

    $model = new ModelForm();

    if ($model->load(Yii::$app->request->post()) && $model->save()) {
        Yii::$app->session->setFlash('success', 'Success');
    } else {
        $footer .= Html::submitButton('Ok', ['class' => 'btn btn-primary']);
    }

    $data = [
        'title' => 'Title',
        'body' => $this->renderAjax('modal-test', [
            'model' => $model,
        ]),
        'footer' => $footer,
    ];

    return Json::encode($data);
}

ReCaptcha

use himiklab\yii2\recaptcha\ReCaptcha;

echo ReCaptcha::widget();

$js = <<<JS
if (typeof grecaptcha !== 'undefined') {
    recaptchaOnloadCallback();
}
JS;
$this->registerJs($js);