表单不提交数据
form doesn't submit data
我在提交表单时遇到了令人沮丧的问题。我的函数都被调用(通过日志文件检查),但请求 ->post('..') 不返回任何内容。我将永远感谢任何帮助解决这个头痛的人。
表单包含一个按钮,单击时调用JavaScript函数addAllToCartProject()。 此函数调用初始 PHP 文件中的 addAll 函数,我尝试从表单中获取数据但没有成功。
我正在处理的代码是用于OpenCart模块的。
模板文件---> project_edit.tpl
<div id="tab-products" class="tab-content">
<form method="post" enctype="multipart/form-data" id="form2">
<div class="buttons"><div class="left">
<input type="button" value="<?php echo $button_add_products; ?>" id="pselect" class="button" />
<input type="button" value="<?php echo $button_add_all_cart; ?>" id="addallltocart" onclick="addAllToCartProject();" class="button" />
<input type="button" value="<?php echo $button_print; ?>" id="printproject" class="button" />
</div></div>
<div class="cart-info">
<table>
.
.
.
</table>
<input type="hidden" name="akey" value="<?php echo $akey; ?>" />
<input type="hidden" name="eid" value="<?php echo $eid; ?>" />
</form>
</div>
JavaScript函数
function addAllToCartProject() {
$.ajax({
url: 'index.php?route=account/projects/addAll',
type: 'post',
data: $('#form2').serialize(),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, .information, .error').remove();
if (json['error']) {
$('#notification').html('<div class="warning" style="display: none;">' + json['error'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.warning').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
} else {
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
$('.success').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
}
}
});
}
PHP 文件-->项目.php
.
.
.
if (isset($this->request->get['project_id'])) {
$printlink = $this->url->link('projects/projects_print', 'project_id=' . $eid . '&akey=' . $akey);
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/projects_edit.tpl')) {
$this->template = $this->config->get('config_template') . '/template/account/projects_edit.tpl';
} else {
$this->template = 'default/template/account/projects_edit.tpl';
}
} else { ..............}
.
.
.
public function addAll() {
$this->language->load('checkout/cart');
$this->language->load('account/projects');
$this->load->model('account/projects');
if (isset($this->request->post['eid'])) {
$eid = $this->request->post['eid'];
} else {
$eid = '0';
$file="log.txt";
$log=fopen($file,'a');
fwrite($log,"'n eid is not set ");
fclose($log);
}
if (isset($this->request->post['akey'])) {
$akey = $this->request->post['akey'];
} else {
$akey = '0';
$file="log.txt";
$log=fopen($file,'a');
fwrite($log,"'n akey is not set ");
fclose($log);
}
.
.
.
}
可以尝试为您的表单元素赋予名称属性:
<div id="tab-products" class="tab-content">
<form method="post" enctype="multipart/form-data" id="form2">
<div class="buttons"><div class="left">
<input name = "products" type="button" value="<?php echo $button_add_products; ?>" id="pselect" class="button" />
<input name = "cart" type="button" value="<?php echo $button_add_all_cart; ?>" id="addallltocart" onclick="addAllToCartProject();" class="button" />
<input name = "print" type="button" value="<?php echo $button_print; ?>" id="printproject" class="button" />
</div></div>
<div class="cart-info">
<table>
.
.
.
</table>
<input type="hidden" name="akey" value="<?php echo $akey; ?>" />
<input type="hidden" name="eid" value="<?php echo $eid; ?>" />
</form>
</div>
相关文章:
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 在php中提交数据时,如果某些值为null,而某些值为非null,如何进行查询
- 如何在不重新加载的情况下提交表单,并使用Node+Express将数据传递回同一页面
- 如何将本地存储数据提交到 Django
- Javascript:使用表单与不使用表单进行数据提交
- writeln img src将数据提交到外部系统-Firefox和IE挂起
- 表单将数据提交到数据库和url
- 根据 Ajax 返回的数据提交表单
- 如何在没有AJAX的情况下将数据提交到CouchDB(使用普通形式的PUT)
- 创建新记录并使用成员数据提交事务
- 在将数据提交到数据库后,点击代码点火器按钮,用DOMPDF生成PDF
- 如何避免struts1.1中的双重数据提交
- 为什么我的Javascript不添加数据提交
- jQuery AJAX PUT请求数据提交不工作
- 如果信息无效,则使用jquery、Ajax将数据提交到数据库
- 使用从另一个表单接收到的数据提交登录表单
- AngularJS–将数据提交到新的url
- 烬数据不发送数据提交
- Javascript或Jquery检测页面刷新和重定向到错误页面-避免重复的数据提交
- 以下数据提交方法的缺点是什么?