I have a widget which works perfectly fine when I use it in layout files however as soon as I use it outside of a layout files say in my index view it displays but when the form is submitted no validation is done and I just get redirected to /index even thought the form action isn’t even set to /index.
Below is my code
Widget (common/widgets/NewsletterWidget.php)
<?php
namespace common\widgets;
use yii\base\Widget;
use frontend\models\Newsletter;
use yii\data\ActiveDataProvider;
use Yii;
/**
* TestWidget
*/
class NewsletterWidget extends Widget
{
public function run()
{
$model = new Newsletter();
return $this->render('newsletterform', [
'model' => $model
]);
}
}
View (common/widgets/views/NewsletterForm.php)
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<?php $form = ActiveForm::begin(['action' => '/newsletter/newslettersignup',]); ?>
<?= $form->field($model, 'email')->textInput(array('placeholder' => 'Enter Email Address'))->label(false) ?>
<div class="form-group field-newsletter-buttom">
<?= Html::submitButton(Yii::t('app', 'Join Now'), ['class' => 'newsletter-btn', 'name' => 'subscribe-button']) ?>
</div>
<?php ActiveForm::end(); ?>
C