[英]CakePHP form will not submit as Post method and returns no data
我在Cake中創建身份驗證。 我在register.ctp中有以下代碼
<?php echo $this->Form->create('User'); ?>
<div class="col-sm-12">
<div class="form-group">
<?php
echo $this->Form->input('email', array('class' => 'form-control'));
echo $this->Form->input('first_name', array('class' => 'form-control'));
echo $this->Form->input('last_name', array('class' => 'form-control'));
echo $this->Form->input('phone', array('class' => 'form-control'));
echo $this->Form->input('password', array('class' => 'form-control'));
echo $this->Form->input('password_confirmation', array('type'=>'password', 'class' => 'form-control'));
echo $this->Recaptcha->show(array('theme' => 'white'));
echo $this->Recaptcha->error();
?>
<p>
<?php
echo $this->Form->end(array('label' => 'Register', 'class' =>"btn btn-lg btn-block ". $this->Buttons->color($account['Config']['theme'])));
?>
</p>
在我的UsersController.php中,我有:
public function register() {
if ($this->request->is('post')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash('Your account has been registered. Please check your email.');
$this->redirect(array('action' => 'account'));
} else {
$this->Session->setFlash('The user could not be saved. Please, try again.');
}
}
$this->set('title', 'Registration');
}
現在,當我提交表單時,它將輸入字段作為GET方法追加到URL的末尾,並且沒有數據傳遞到控制器。 這是呈現的html代碼:
<form action="/users/register" id="UserRegisterForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input type="hidden" name="_method" value="POST" />
</div>
<div class="col-sm-12">
<div class="form-group">
<div class="input email required">
<label for="UserEmail">Email</label>
<input name="data[User][email]" class="form-control" maxlength="255" type="email" id="UserEmail" required="required" />
</div>
<div class="input text required">
<label for="UserFirstName">First Name</label>
<input name="data[User][first_name]" class="form-control" maxlength="100" type="text" id="UserFirstName" required="required" />
</div>
<div class="input text required">
<label for="UserLastName">Last Name</label>
<input name="data[User][last_name]" class="form-control" maxlength="100" type="text" id="UserLastName" required="required" />
</div>
<div class="input tel required">
<label for="UserPhone">Phone</label>
<input name="data[User][phone]" class="form-control" maxlength="20" type="tel" id="UserPhone" required="required" />
</div>
<div class="input password required">
<label for="UserPassword">Password</label>
<input name="data[User][password]" class="form-control" type="password" id="UserPassword" required="required" />
</div>
<div class="input password required">
<label for="UserPasswordConfirmation">Password Confirmation</label>
<input name="data[User][password_confirmation]" class="form-control" type="password" id="UserPasswordConfirmation" required="required" />
</div>
<script>
var RecaptchaOptions = {
"theme": "white"
};
</script>
<script type="text/javascript" src="http://www.google.com/recaptcha/api/challenge?k=6LcDOecSAAAAAPgyYLxxtad0urkh9f-AgJ1IYLDE"></script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=6LcDOecSAAAAAPgyYLxxtad0urkh9f-AgJ1IYLDE" height="300" width="500" frameborder="0"></iframe>
<br/>
<textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
<input type="hidden" name="recaptcha_response_field" value="manual_challenge" />
</noscript>
<p>
<div class="submit">
<input class="btn btn-lg btn-block btn-warning" type="submit" value="Register" />
</div>
我似乎找不到問題。 也許,這里有人會知道答案。
謝謝,格雷格
問題可能在於驗證碼的使用。 我不知道這是如何實現的,但是可能會影響表格。 嘗試將其刪除,看看是否有幫助。
另外,您可能應該在同一div中啟動表單,如下所示:
<div class="col-sm-12">
<div class="form-group">
<?php
// Start the form
echo $this->Form->create('User');
echo $this->Form->input('email', array('class' => 'form-control'));
echo $this->Form->input('first_name', array('class' => 'form-control'));
echo $this->Form->input('last_name', array('class' => 'form-control'));
echo $this->Form->input('phone', array('class' => 'form-control'));
echo $this->Form->input('password', array('class' => 'form-control'));
echo $this->Form->input('password_confirmation', array('type'=>'password', 'class' => 'form-control'));
echo $this->Recaptcha->show(array('theme' => 'white'));
echo $this->Recaptcha->error();
?>
<p>
<?php
// End the form
echo $this->Form->end(array('label' => 'Register', 'class' =>"btn btn-lg btn-block ". $this->Buttons->color($account['Config']['theme'])));
?>
</p>
</div>
</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.