开发者

Error getting $_POST parameters

I'm stuck with this. Turns out i am using a JUI dialog for the user to input a required password. This is the code of the view which is called by the JUI dialog:

<div class="passwordRequestDialog">
<?php 
$form=$this->beginWidget('CActiveForm', array(
                                'id'=>'requestpassword-form',
                                'enableAjaxValidation'=>false,
                                'clientOptions'=>array('validateOnSubmit'=>false),
                                'htmlOptions'=>array('enctype'=>'multipart/form-data'),
                        )); 
?>

<开发者_如何学JAVA;div class="row">   
    <?php echo CHtml::activeHiddenField($model,'idLiga_hidden',array('value'=>$model->id)); ?>
    <?php echo CHtml::label("Ingrese la contrasenia de la liga $model->id?",false, array('style'=>'{font-weight:bold;font-size:12px;}')); ?>
    <?php echo CHtml::activePasswordField($model,'password',array('value'=>'')); ?>
</div>

<div class="row buttons">
    <?php echo CHtml::submitButton("Guardar"); ?>
</div> 

<?php $this->endWidget(); ?>
</div>

However, when i click on the submit button, i can see with firebug the post parameters:

this LigasDeAmigos%5BidLiga_hidden%5D=2&LigasDeAmigos%5Bpassword%5D=typedInPassword

Out of despair, I have tried to get the post parameter in many different ways:

$password = $_POST['this']['password'];
$password = $_POST['this']['LigasDeAmigos']['password'];
$password = $_POST['this']['LigasDeAmigos[password]'];

None of them work... the first one returns always the same value: "L". I am assuming it is getting the first letter out of the whole "this" parameter. The second one gives an error and so does the third one. Any help is more than welcome!

Edit as suggested by @Jon print_r($_REQUEST) output

Array
(
    [idLiga] => 2
    [this] => LigasDeAmigos%5BidLiga_hidden%5D=2&LigasDeAmigos%5Bpassword%5D=pass
)

Any ideas?


Well, I don't know why the parameters are getting in like this (haven't done this particular scenario) so I can't suggest a solution that strikes at the heart of the problem (assuming there is a problem).

However, you can parse the parameters yourself like this:

// Normally this would be $form = $_POST['this'], but for the example...
$form = 'LigasDeAmigos%5BidLiga_hidden%5D=2&LigasDeAmigos%5Bpassword%5D=pass';

parse_str($form, $vars);
print_r($vars);

// You can now access the variables as in:
$id = $vars['idLiga_hidden'];
$password = $vars['pass'];

See it in action.


I would tie it to a model.

Using your fields in your view, for example, your model would resemble:

class TestForm extends CFormModel
{

    public $id;
    public $password;
    public $idLiga_hidden;

    public function rules ()
    {
        return array (
            array ('password', 'required'),
            array ('id, idLiga_hidden', 'verify'),
        );
    }

    public function verify ($attribute, $params)
    {
        //$this->addError('idLiga_hidden','Incorrect dumaflache');
    }

}

Note that you need to define some 'rules' for the attribute assignment to work. Then, you can reference the model in your controller:

public function actionTest ()
{
    if (isset ($_POST['TestForm']))
    {
        $model = new TestForm();
        $model->attributes = $_POST['TestForm'];
        echo $model->password;
    }
    else
    {
        $model = new TestForm();
        $this->render ('test', array ('model' => $model));
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜