我在文件form.php中有这样的搜索表单。它工作得很好,我面临的问题是我使用类/方法(函数)。例如,我有这种方法调用徽标和manu吧。
//$this->output is just a method that echos, that's all it does
function header()
{
$this->output('<DIV CLASS="header">');
$this->logo();
include('form.php');
$this->links();
$this->header_clear();
$this->output('</DIV>');
}
与上面一样,表单显示完美,但是当我选择一个类别时,它会将我带到form.php,它会破坏一切。 (form.php只是一种形式)
我知道问题在这里
onChange="javascript:this.form.action='form.php';
this.form.submit()
没有javascript我无法获取类别值,页面不刷新,所以$ _POST ['cat']为空。
有什么更好的方法来刷新页面而不会把我带到另一个页面?
我知道这可能令人困惑,只要忍受我。
<form enctype="multipart/form-data" name="form" id="form" action="form.php"
method="get">
<SELECT name="cat" onChange="javascript:this.form.action='form.php';
this.form.submit()">
<option value="" >Categories</option>
<?php
$z = "0" ;
//Select categories form database
$category =db_select_categories($z);
if(is_array($category))
{
foreach($category as $rowc)
{
$id_cat = htmlentities($rowc['id_cat'], ENT_QUOTES);
$cat_name = htmlentities($rowc['cat_name'], ENT_QUOTES, 'utf-8');
$cat_name = stripslashes($cat_name);
echo "<option style=\"background-color:#FFCC99\" disabled>".$cat_name."
</option>";
$categories = db_select_categories($id_cat);
if(is_array($categories))
{
foreach($categories as $row)
{
$id = htmlentities($row['id_cat'], ENT_QUOTES);
$name = htmlentities($row['cat_name'], ENT_QUOTES, 'utf-8');
$name = stripslashes($name);
if ( $cat == $id )
{
echo "<option value='".$id."'selected> ".$name."</option>";
}
else
{
echo "<option value=".$id."> ".$name."</option>";
}
}
}
}
}
echo "</SELECT>";
?>
<div>
<?php
if(!empty($cat))
{
//Outputs a populated select option depending on category
display_search_options($cat);
}
?>
</div>
答案 0 :(得分:0)
如果你不想让它去表格,那就把它带到其他地方......
onChange="javascript:this.form.action='index.php';
this.form.submit()