我希望將$ module_id和$ user_name傳遞給url。點擊按鈕提交後,如何將下拉列表中的選定值傳遞給url查詢字符串?
下面的代碼不會將正確的值從下拉列表傳遞到URL查詢字符串。你能告訴我什麼是缺少的?
<?php
$root = $_SERVER['HTTP_HOST'];
$fullname = $_POST['user_name'];
$user_name = explode(" ", $fullname);
$module_id = $_POST['e_learning_module'];
?>
<form action="<?php echo home_url() . '/certificate/print-request-certificate.php?id=' . $module_id . '&fname=' . $user_name[0] . '&lname=' . $user_name[1]; ?>" method="post" name="">
<select id="user_name" name="user_name">
<option value="default">Names</option>
<?php
$query = mysql_query('SELECT DISTINCT fname, lname FROM wl_activity_logs ORDER BY fname ASC');
while($row = mysql_fetch_array($query)) {
echo '<option value="' . htmlentities($row['fname'], ENT_QUOTES) . ' ' . htmlentities($row['lname'], ENT_QUOTES) . '">' . htmlentities($row['fname'], ENT_QUOTES) . ' ' . htmlentities($row['lname'], ENT_QUOTES) . '</option>';
}
?>
</select>
<input type="hidden" name="user_name" id="user_name_hidden">
<select id='e_learning_module' name="e_learning_module">
<option value="default">E-Learning Modules</option>
<?php
global $post;
$args = array(
'numberposts' => -1,
'post_type' => 'wpsc-product',
'post_status' => 'publish',
'wpsc_product_category' => 'e-learning-modules',
'order' => 'ASC'
);
$e_learning_modules = get_posts($args);
foreach($e_learning_modules as $post) {
setup_postdata($post);
$id = $post->ID;
?>
<option value="<? echo $id; ?>"><?php the_title(); ?></option>
<?php
}
?>
</select>
<input type="hidden" name="e_learning_module" id="e_learning_module_hidden">
<input type="submit" value="Print" name='print' />
</form>
爲什麼不添加它們作爲隱藏字段。表單方法是POST並使用$ _POST,這些值可以被捕獲。 –