簡體   English   中英

單擊按鈕提交后,如何將下拉列表中的選定值傳遞給url查詢字符串?

[英]How can I pass the selected values from the dropdown list to the url query string when button submit is clicked?

我希望將$ module_id和$ user_name傳遞給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> 

更改

<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="">

<form action="<?php echo home_url() . '/certificate/print-request-certificate.php" method="GET" name="">

在表單標簽下面添加以下代碼

<input type="hidden" name="id" value="<?php echo $module_id?>"> <input type="hidden" name="fname" value="<?php echo $user_name[0]?>"> <input type="hidden" name="lname" value="<?php echo $user_name[1]?>">

您有2個名稱相同的字段“ user_name”:

<select id="user_name" name="user_name"></select>

<input type="hidden" name="user_name" id="user_name_hidden">

您需要將第二個更改為另一個名稱(例如: user_name_hidden )或將第一個更改為另一個名稱(例如: full_name ),然后使用$fullname = $_POST['full_name'];

您必須使用form methode作為'get'( method="get" ),如下所示。

<form action="<?php echo home_url() . '/certificate/print-request-certificate.php?id=' . $module_id . '&fname=' . $user_name[0] . '&lname=' . $user_name[1]; ?>" method="get" name="">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM