0
votes

I have a form to add a new user. Only an admin who is logged in may access this form. Unfortunately, the username and the password of the admin are filled into the form fields which are expected to be completely clear. And one really strange thing is: The username is printed into the birthday field!

I really cannot explain myself how it works. And I could not found in the WWW any post from a person who has got the same problem - I only found questions and answers about pre-filled form data that is wanted.

This is the View /Users/add.ctp

<h1>Add a new Member</h1>
<?php echo $this->Form->create('User', array('url' => BASE_URL.'/users/add', 'action'=>'post')); ?>
<table class="form">
     <tr><td>Username:</td><td><?php echo $this->Form->input('User.username', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
     <tr><td>Name:</td><td><?php echo $this->Form->input('User.name', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
     <tr><td>Lastname:</td><td><?php echo $this->Form->input('User.lastname', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
     <tr><td>E-Mail:</td><td><?php echo $this->Form->input('User.email', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
     <tr><td>Birthday:</td><td><?php echo $this->Form->input('User.birth', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
     <tr><td>Password:</td><td><?php echo $this->Form->input('User.password', array('label' => false, 'div' => false, 'value' => ''));?></td></tr>
</table>

<?php 
     echo $this->Form->submit('Submit', array('formnovalidate' => true));
     echo $this->Form->end();
?>

And here is the Controller /UsersController.php

public function add() {

    $this->layout = 'admin';

    if ($this->request->is('post')) {
        // Saving the data
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            $this->Session->setFlash(__('Data saved.'));
            return $this->redirect(array('action' => 'view'));
        }
        $this->Session->setFlash(__('Data could not be saved.'));
    }

}

By the way: Saving works fine. Of course, the admin is of Object User, as is the new member to be added. I think, here lies the problem, but I really do not know... I am thinking about this problem the whole day :( Does anybody know what to do?

Thanks in advance.

2
'url' and 'action' together make no sense :), also the url should not be declared that complicated, the array syntax using controller and action keys suffices. And drop that "value" stuff, it also breaks your forms on invalidation. Bad idea. Try to be as simple as possible (the less you have to type the better). - mark
Thank you for your comment. I know that cakePHP allows to generate forms in a more comfortable way. But I still need the 'url' thing, because of a really annoying problem with a domain redirecting, which unfortunately is not made by a htaccess but with an iFrame somehow... if I do not declare the url this way, the form would not save anything, give no failure messages, but would only load the form again... Could not do anything against it until now, have to work with what I have :'( - Snoops
Then you can drop the action. Having both in there is useless, as at least one of them doesn't do what it is supposed to do - and will only continue confusing everyone :) - mark

2 Answers

0
votes

Is not your browser? (saved username/password when you type for the first time)

So, you can turn of the autocomplete.

<?php echo $this->Form->create('User', array('url' => BASE_URL.'/users/add', 'action'=>'post', 'autocomplete' => 'off')); ?>

This option => 'autocomplete' => 'off'

0
votes

Check your $this->data.

CakePHP autocompletes forms with data found there because it guesses that is data already submitted by the user.

In you example, if you have some value in $this->data['User']['birth'] it should show that value in the Birthday input.