1

I have CMaskedTextField in my form, when i fill it, the $_POST[] do not return any value for it!?

<?php echo CHtml::label(Yii::t('models', 'form.label.position'), 'position'); ?>
    <?php
    $this->widget('CMaskedTextField', array(
            'model' => null,
            'name' => "position",
            'mask' => '999',
            'htmlOptions' => array(
            'size' => 5,
            'placeholder' => Yii::t('models', 'form.hint.position'),
            'title' => Yii::t('models', 'form.hint.position'),
            ),
    ));
    ?>
Mostafa -T
  • 730
  • 8
  • 19
shgnInc
  • 2,054
  • 1
  • 23
  • 34

1 Answers1

0

You can try remove 'model' => null like:

<?php echo CHtml::label(Yii::t('models', 'form.label.position'), 'position'); ?>
    <?php
    $this->widget('CMaskedTextField', array(
            'name' => "position",
            'mask' => '999',
            'htmlOptions' => array(
            'size' => 5,
            'placeholder' => Yii::t('models', 'form.hint.position'),
            'title' => Yii::t('models', 'form.hint.position'),
            ),
    ));
    ?>

In your widget, If you want to use your model then you should remove name and add attribute.

Updated

In my form: I have a view with the form like:

<?php echo CHtml::beginForm('post/test', 'post'); ?>

    <?php echo CHtml::errorSummary($model); ?>

    <div class="row">
        <?php echo CHtml::label(Yii::t('models', 'form.label.position'), 'position'); >
    <?php
    $this->widget('CMaskedTextField', array(            
            'name' => "position",
            'mask' => '999',
            'htmlOptions' => array(
            'size' => 5,
            'placeholder' => 'place holder',
            'title' => 'title'
            ),
    ));
    ?>
    </div>

    <div class="row submit">
        <?php echo CHtml::submitButton('test'); ?>
    </div>

<?php echo CHtml::endForm(); ?>

And I also have a PostController that contains test action like:

public function actionTest()
    {       
        var_dump($_POST);
    }

It's working fine.

array (size=2)
  'position' => string '234' (length=3)
  'yt0' => string 'test' (length=4)

So please make sure you have the Form is sent by POST method and it's submitted after you filled your maskedTextField.

secretlm
  • 2,361
  • 2
  • 27
  • 38
  • Thank you, But your answer not correct, i don't have any model for it so as you said i remove `'model' => null` but $_POST['position'] is empty.... – shgnInc Nov 27 '13 at 16:41
  • Yea, I really sure about the method of the form is post, because i have some other fields are sent correctly by it. `echo CHtml::beginForm($this->createUrl('create', array('form' => $form_id)), 'post', array('id' => 'form-id',));` – shgnInc Nov 29 '13 at 16:24