Monday, November 29, 2010

Re: $_POST is populated with the form data, but $this->data is always empty

Why are you setting NULL as your form model?

Try:
<?php echo $form->create('User',
array(
'default' => true,
'inputDefaults' => array(
'label' => false,
'div' => false
)
)
);

Try looking in params. I'm guessing it's being passed in as
params['form'].

HTH,
Nick

On Nov 29, 11:56 am, amfriedman <amfried...@gmail.com> wrote:
> Hey folks
>
> This is a very strange issue indeed, and at its root it is NOT related
> to this post that declares a similar symptom:http://groups.google.com/group/cake-php/browse_thread/thread/840eaa08...
>
> I have a form in /users/view/.  When I submit it and check $_POST and
> $this->data at the very beginning of AppController->beforeFilter(),
> the form data appears in the $_POST array but $this->data does not
> have any data.  In fact, $this->data is not even set by Cake!
>
> The Auth component is removed from the $components list, so I know
> that Auth is not the culprit.  I've also tried to test this form in
> different controllers/views, and I get the same problem.  Pretty
> scary, huh?
>
> --------------------------------------------------------------------------- ------------
> Here is the view code (I've also tried setting the form->create()
> first argument with a model of 'User' and used full Model.field dot
> notation for my inputs):
> --------------------------------------------------------------------------- ------------
>
>     <?php echo $form->create(NULL,
>                         array(
>                                   'default' => true,
>                                   'inputDefaults' => array(
>                                         'label' => false,
>                                         'div' => false
>                                   )
>                         )
>
>                   ); // default => onsubmit true/false  ?>
>
>                          <?php echo $form->input('username', array('size'=> 20, 'maxlength'
> => 50)); ?>
>
>                          <?php echo $form->input('pw', array('type' => 'password',
> 'size'=> 20, 'maxlength' => 50)); ?>
>
>                         <?php echo $form->submit('Log In &raquo;', array('class' =>
> 'submit', 'name' => 'submit',  'title' => 'Enter your username and
> password for access.', 'class' => 'button', 'escape' => false)); ?>
>
>         <?php echo $form->end(); ?>
>
> --------------------------------------------------------------------------- ------------
> Here is the app_controller:
> --------------------------------------------------------------------------- ------------
>         function beforeFilter() {
>
>                 pr(__CLASS__.'::'.__FUNCTION__.'()...');
>
>                 pr('POST data: ');
>                 pr($_POST);
>
>                 if(isset($this->data)) {
>                         pr('this->data: ');
>                         pr($this->data);
>                 } else { pr('this->data not set!'); }
>        // ...
>    }
>
> --------------------------------------------------------------------------- ------------
> Here is the browser output:
> --------------------------------------------------------------------------- ------------
>    AppController::beforeFilter()...
>
> POST data:
>
> Array
> (
>     [_method] => POST
>     [data] => Array
>         (
>             [User] => Array
>                 (
>                     [username] => testuser
>                     [pw] => 12345
>                 )
>
>         )
>
>     [submit] => Log In »
> )
>
> this->data not set!

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: