gpt4 book ai didi

php - CakePHP 表单提交不工作

转载 作者:搜寻专家 更新时间:2023-10-31 22:01:28 25 4
gpt4 key购买 nike

我刚开始使用 CakePHP,我想创建一个表单,当它被提交时它会调用 Controller 中的一个函数。我正在使用 CakePHP 2.6 版

我目前的代码是:

查看:

<div class="modal-body">
<?php echo $this->Form->create('Tweet', array('url' => array('controller' => 'posts', 'action' => 'postTweet'))); ?>
<?php echo $this->Form->textarea('Tweet', array('class' => 'form-control','rows' => '3', 'placeholder' => "what's happening?", 'maxlength' => '140', 'label' => false)); ?>
<?php echo $this->Form->button('Close', array('class' => 'btn btn-default', 'data-dismiss' => 'modal', 'type' => 'button'));?>
<?php echo $this->Form->submit('Tweet', array('class' => 'btn btn-primary', 'type' => 'submit', 'div' => false)); ?>
<?php echo $this->Form->end(); ?>
</div>

帖子 Controller :

    public function postTweet(){
//check if post is being made
if ($this->request->is('post')) {
//do something
}
}

页面上的 HTML:

<form action="/posts/postTweet" id="TweetIndexForm" method="post" accept-charset="utf-8">
<div style="display:none;">
<input name="_method" value="POST" type="hidden">
</div>
<textarea name="data[Tweet][Tweet]" class="form-control" rows="3" placeholder="what's happening?" maxlength="140" id="TweetTweet"></textarea>
<button class="btn btn-default" data-dismiss="modal" type="button">Close</button>
<input class="btn btn-primary" value="Tweet" type="submit">
</form>

问题是当我点击提交按钮时没有任何反应,我已经检查了 Firebug,控制台选项卡中没有错误,网络选项卡中没有进行 POST,错误日志中也没有记录任何错误。非常感谢任何帮助。

编辑:解决了我有 JavaScript 阻止提交表单感谢您的帮助!

最佳答案

使用类似提交 ->

echo $this->Form->submit('Tweet', array('label' => false, 'name' => 'submit', 'class' => 'grayBTN', 'title' => '', 'alt' => 'Submit', 'error' => false));

我一直在用它。

您提交的问题是您的代码中使用了 'type' => 'submit' 并且您还指定了 $this->Form->submit

如果您指定的 Button 类型为 submit 那么它就可以了 ->

echo $this->Form->button('Submit Form', array('type' => 'submit'));

但是在你的情况下你有 $this->Form->submit.. 所以你不需要明确指定它。

关于php - CakePHP 表单提交不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28340380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com