我有一個文件'functions.php',其中包含幾個方法。其中一種方法是顯示包含一個下拉列表的GET表單。php在同一個php文件中獲取表單動作
<form action="" method="GET">
<select name="123_cat" class ="styled" onchange="this.form.submit();">
<?php foreach($subcategories['categories'] as $sc) { ?>
<optgroup label="<?php echo $sc['name']; ?>">
<?php foreach ($sc['subcategories'] as $ss){?>
<option id = "123_cat" value="<?php echo $ss['sid']; ?>" <?php if (isset($_GET['123_cat'])) { if($ss['sid'] == $_GET['123_cat']) echo 'selected = "selected"';} else { if(in_array($ss['sid'], $the_subcategories)) echo 'selected = "selected"'; } ?>><?php echo $ss['name']; ?></option>
<?php }?>
在那之後,我有相同的functions.php拋出我一些類別的一個JSON的方法。
function get_deals($subcategories = array(), $page = 0, $deals_per_page = 10, $city = "bucuresti",$format = "json")
{
global $wpdb;
$site_root = "https://123reduceri.ro/";
$api_root = "api/v3/";
$table_name = $wpdb->prefix . "123reduceri";
$my_data = $wpdb->get_row("SELECT * FROM $table_name ORDER BY time DESC LIMIT 1");
$token = $my_data->token;
if(isset($_GET['123_city'])){
$city = $_GET['123_city'];
}
else{
$city = $my_data->city;
}
if(isset($_GET['123_cat'])){
$subcategories = array($_GET['123_cat']);
}
else{
$subcategories = unserialize($my_data->categories);
}
$url = $site_root . $api_root .$city . "." . $format . "?token=" . $token . "&white_label=1" . "&deals_per_page=" . $deals_per_page;
if($page)
{
$url .= "&page=" . $page;
}
if(count($subcategories))
{
$subcategories_string = implode(",", $subcategories);
$subcategories_string = rtrim($subcategories_string, ",");
$url .= "/".$city."?"."&subcategories=" . $subcategories_string;
}
$response = file_get_contents($url);
if($format == "json")
return json_decode($response, TRUE);
return $response;
}
我的問題是提交GET表單後,我想保留在同一頁面中,並根據get_deals方法獲取值。在GET表單的'action'中我應該有什麼? (奇怪的事實是,如果我有一個郵政foveorm它的作品,如果我讓表單行動「」(如上)) 謝謝!
要提交表單後返回到同一頁面離開表單空的action屬性'form action =「」method =「get」' – slash197 2012-03-21 13:19:47
顯示錶單的HTML代碼。 – 2012-03-21 13:19:55
@pinkypower嘗試過,不工作 – dana 2012-03-21 13:22:16