【发布时间】:2014-12-23 15:02:48
【问题描述】:
我目前正在构建一个定义了一些函数的类。第一个函数显示一个表单供用户填写一些属性:
function display_sheet_form($f=array())
{
$count = (isset($f['task_title'])) ? count($f['task_title']) : 3;
if ($count < 3) $count = 3;
echo '<form name="add_sheet" id="dls-sus-modify-sheet" method="post" action="">';
//some additional code here to display the form elements
echo '<input type="hidden" name="mode" value="submitted" />';
echo '<input type="submit" name="Submit" class="button-primary" value="'.esc_attr('Save').'" />';
echo '</form>';
}
然后我有另一个功能要进行表单处理:
function modify_sheet_page()
{
echo "in the modify sheet page";
// Set mode vars
$edit = (empty($_GET['sheet_id'])) ? false : true;
$add = ($edit) ? false : true;
$submitted = (isset($_POST['mode']) && $_POST['mode'] == 'submitted');
$err = 0;
// Process form if submitted
if($submitted) {
//process the form code
}
}
如何在此类中将表单元素直接提交给该函数?
编辑:我包含了一个 Pastebin,所以你可以看到整个代码: http://pastebin.com/MWJXU1hB
【问题讨论】:
-
不,你应该以某种方式调用该函数。
-
在你显示的文件中,你需要检查一下,
$_POST["mode"]是否不为空,如果不是,则其值为save$Class->modify_sheet_page()而不是尝试“如您所说,直接提交。 -
@lolka_bolka 不确定我是否理解,你能给我举个例子来说明你的意思吗?
标签: php