【发布时间】:2016-06-17 00:51:49
【问题描述】:
在完成此表单之前,我还有最后一张,但我认为我所依据的模板中的功能使事情变得有些复杂。基本上我希望在提交按钮执行其命令之前需要一个“同意”复选框。
$tbl->addRow();
$tbl->addCell( $frm->addInput('checkbox', 'checkbox', 'check'),
'submit', 'data', array('colspan'=>4) );
$tbl->addRow();
$tbl->addCell( $frm->addInput('submit', 'submit', 'Submit'),
'submit', 'data', array('colspan'=>4, 'onclick'=>'if(!this.form.checkbox.checked)return false};',) );
$frmStr = $frm->startForm('result.php', 'post', '', array('onsubmit'=>'return checkSubmit(this);') ) .
$tbl->display() . $frm->endForm();
return $frmStr;
}
这是我的提交/复选框的 php。下面是被调用来创建行/单元格/输入的函数。使用这种格式,我不能简单地添加标签,我认为这是阻碍我前进的原因。
function addCell($data = '', $klass = '', $type = 'data', $attr_ar = array() ) {
$cell = array(
'data' => $data,
'klass' => $klass,
'type' => $type,
'atts' => $attr_ar
);
if ( empty($this->cur_section['rows']) ) {
try {
throw new Exception('You need to addRow before you can addCell');
} catch(Exception $ex) {
$msg = $ex->getMessage();
echo "<p>Error: $msg</p>";
}
}
// add to current section's current row's list of cells
$count = count( $this->cur_section['rows'] );
$curRow = &$this->cur_section['rows'][$count-1];
$curRow['cells'][] = &$cell;
}
function addInput($type, $name, $value, $attr_ar = array() ) {
$str = "<input type=\"$type\" name=\"$name\" value=\"$value\"";
if ($attr_ar) {
$str .= $this->addAttributes( $attr_ar );
}
$str .= $this->xhtml? ' />': '>';
return $str;
}
如果有帮助,很高兴分享更多代码。谁能帮我正确格式化代码以适应 addInput 函数内的“数组”参数?
【问题讨论】:
-
你用的是什么框架?
-
对不起,你说的框架是什么意思?只是我使用一些 js 函数获取的 php 模板,如果这就是您的意思,这就是我要构建的内容:dyn-web.com/php/order_form/example2.php
-
@sixfiveoh PHP 在表单提交之前不能做任何事情。 PHP 运行在服务器上,而不是客户端。
标签: php forms checkbox form-submit submit-button