Can't Get Value From Cactiveform In Module

I have a module and I’m doing login form for the module. This is the code for login view:

<?php

$form = $this->beginWidget(‘CActiveForm’, array(

'id' =&gt; 'login-form',


'enableClientValidation' =&gt; true,


'clientOptions' =&gt; array(


	'validateOnSubmit' =&gt; true,


),

));

?>

&lt;div class=&quot;row ri&quot;&gt;


	&lt;?php echo &#036;form-&gt;label(&#036;model, 'username', array('class' =&gt; 'leftlabel')); ?&gt;


	&lt;div class=&quot;fakeInput&quot;&gt;&lt;?php echo &#036;form-&gt;textField(&#036;model, 'username'); ?&gt;&lt;/div&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model, 'username'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row ri&quot;&gt;


	&lt;?php echo &#036;form-&gt;label(&#036;model, 'password', array('class' =&gt; 'leftlabel')); ?&gt;


	&lt;div class=&quot;fakeInput&quot;&gt;&lt;?php echo &#036;form-&gt;passwordField(&#036;model,'password'); ?&gt;&lt;/div&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model, 'password'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;ovh&quot;&gt;


	&lt;?php echo &#036;form-&gt;error(&#036;model, 'messages'); ?&gt;


&lt;/div&gt;





&lt;div class=&quot;row rememberMe&quot;&gt;


	&lt;div class=&quot;leftside&quot;&gt;


		&lt;?php echo &#036;form-&gt;checkBox(&#036;model,'rememberMe'); ?&gt;


		&lt;?php echo &#036;form-&gt;label(&#036;model,'rememberMe', array('class'=&gt;'lblremember')); ?&gt;


		&lt;?php echo &#036;form-&gt;error(&#036;model,'rememberMe'); ?&gt;


	&lt;/div&gt;


	&lt;?php echo CHtml::submitButton('Login', array('class'=&gt;'btnLogin')); ?&gt;


&lt;/div&gt;

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

My question is: why I can’t get the post value from the form? I viewed the page source code it has something like: <input name=“LoginForm[username]” id=“LoginForm_username” type=“text” maxlength=“30”> and I always get null POST value from the form but when I change the input name to <input name=“username” …> I can get the value from the form.

Anyone has any idea how to solve this?

Thanks

Hi dara,

It’s probably because you are trying to get the POST values in a wrong way, like:




if (isset($_POST['username'])

    $username = $_POST['username'];



Review the "Working with Forms" sections of the guide.

http://www.yiiframework.com/doc/guide/1.1/en/form.action

Thanks for replied. It’s true I can the value from POST by doing that

if (isset($_POST[‘username’])

&#036;username = &#036;_POST['username'];

but what I’m trying to get the value from POST is something like

if (isset($_POST[‘LoginForm[username]’])

&#036;username = &#036;_POST['LoginForm[username]'];

I want to get the value in array from form. It works when it’s a standalone application but it doesn’t work when I use it as a module.

Well try to var_dump($_POST) to see where your error is :slight_smile:

Hint: [font=“Courier New”]$_POST[‘LoginForm[username]’][/font] is incorrect