我有一个'functions.php'文件,其中包含多种方法。其中一种方法是显示包含一个下拉列表的GET表单。
<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表格的“行动”中拥有什么? (奇怪的事实是,如果我有一个POST foveorm它可以工作,如果我让表单行动“”(如上)) 谢谢!
答案 0 :(得分:0)
使用action = '".$_SERVER['PHP_SELF']."'
答案 1 :(得分:-1)
您可以使用jQuery and the .ajax()方法从脚本中检索值。
答案 2 :(得分:-1)
只需将操作设置为您当前所在页面的网址(不包括获取参数)