Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use SettingAction form a custom form #49

Open
rizrob66 opened this issue May 10, 2016 · 9 comments
Open

Cannot use SettingAction form a custom form #49

rizrob66 opened this issue May 10, 2016 · 9 comments

Comments

@rizrob66
Copy link

Hi,
I tried to use SettingAction to make a custom form to handle a setting category. There are several things I did not understand, so it doesn't work. Could you please provide an fully working example?
thanks Roberto

@arisk
Copy link
Contributor

arisk commented May 10, 2016

Hi Roberto. There's an example of how to use the settings action in the readme file. If you have any problems with those instructions please show me what you have so far and I'll try to help you get it working.

@rizrob66
Copy link
Author

rizrob66 commented May 12, 2016

Thanks arisk,
I work with basic and made the model in models\AziendaSettings.php directory:

<?php
namespace app\models;
use Yii;
class AziendaSettings extends \yii\base\Model {
    public $titolare, $telefono;
    public function rules()
    {
        return [
            [['titolare', 'telefono'],
        ];
    }

    public function fields()
    {
            return ['titolare', 'telefono'];
    }

    public function attributes()
    {
            return ['titolare', 'telefono'];
    }
}

in views\site\azienda-settings.php

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<?php $form = ActiveForm::begin(['id' => 'azienda-settings-form']); ?>

<?= $form->field($model, 'titolare') ?>
<?= $form->field($model, 'telefono') ?>

<?php ActiveForm::end(); ?>

in controllers\SiteController.php:

  public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
            ],

        'azienda-settings' => [
                'class' => 'pheme\settings\SettingsAction',
                'modelClass' => 'app\models\AziendaSettings',
                //'scenario' => 'site', // Change if you want to re-use the model for multiple setting form.
                'viewName' => 'azienda-settings'   // The form we need to render
            ],            
        ];
    }

when I try index.php?r=site/azienda-settings
There is no submit button and I can't see the actual value of the varable azienda.titolare and azienda.telefono .
You Settings is very usefull,
please help me to complete.

@demogorgorn
Copy link

demogorgorn commented May 18, 2016

I think that you forgot to add submit button in your view:

<?php $form = ActiveForm::begin(['id' => 'social-service-form']); ?>
<?= $form->field($model, 'twitter') ?>
<?= $form->field($model, 'google') ?>
<?= $form->field($model, 'facebook') ?>
<?= $form->field($model, 'youtube') ?>
<?= $form->field($model, 'linkedin') ?>
<?= $form->field($model, 'pinterest') ?>
<?= $form->field($model, 'vimeo') ?>
<?= $form->field($model, 'instagram') ?>
<?= $form->field($model, 'vk') ?>
<?= $form->field($model, 'ok') ?>

<div class="form-group">
        <?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

@rizrob66
Copy link
Author

thanks demogorgorn,
I add the submit button as you suggester and:
Invalid Configuration – yii\base\InvalidConfigException
Unable to locate message source for category 'extensions/yii2-settings/settings'.
.....
Module::t('settings', '{attribute} "{value}" already exists for this section.')
:-(

@arisk
Copy link
Contributor

arisk commented May 30, 2016

Have a look at this comment to configure your translations correctly. #51 (comment)

@rizrob66
Copy link
Author

Yesss!!!!!!! it works!!!!!
Thank you very much indeed!
:-)

@arisk
Copy link
Contributor

arisk commented May 31, 2016

You're welcome :)

@celsoft
Copy link

celsoft commented Dec 26, 2017

I can not make a custom form.

PHP Recoverable Error – yii\base\ErrorException
Object of class stdClass could not be converted to string

clip2net_171226113340

Controller:
clip2net_171226113742

Model:
clip2net_171226113755

print_r($model) in view:
clip2net_171226113930

UPDATE:
If you just save numbers in the text box, then this error occurs. If the text field, then all is well.

@mohdqasim98
Copy link

mohdqasim98 commented Jul 23, 2018

If you just save numbers in the text box, then this error occurs. If the text field, then all is well.

having the same issue. Any fix ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants