문제

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.

도움이 되었습니까?

해결책

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'

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top