Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
442 views
in Technique[技术] by (71.8m points)

javascript - 我有一个按钮可以重定向另一个表单,我希望下拉菜单中的该按钮值作为下一页表单中的选定选项?(I have a button that redirects the another form I want that button value in the dropdown as a selected option in the next page form?)

Here is a code button code(这是一个代码按钮代码)

<h2 class="single-heading"> <?php echo get_the_title(); ?> Review <a href=" <?php echo home_url().'/submit-review/'; ?> " class="btn btn-light text-right pbd-title-btn" id="title" value=" <?php echo get_the_title($post->ID); ?> " > <i class="fa fa-plus" aria-hidden="true"> </i>Write a Review</a> </h2> I want that post or button value in the dropdown list as a selected value.(我希望下拉列表中的帖子或按钮值为选定值。) here is a second page form code(这是第二页表单代码) <div class="col-md-12 col-lg-12 col-xs-12 col-sm-12"> <label class="control-label">Select Breeder Name/Entity <span class="required">*</span></label> <select class="category form-control" data-placeholder="Select an option" id="pbd_review_name" name="pbd_review_name_id" > <option value="">Select an option</option> <?php $res = get_posts(array('post_type' => 'review', 'post_status' => 'publish', 'posts_per_page' => -1)); if(!empty($res)){ foreach($res as $row){ $b_name = $row->post_title; $b_photo = get_post_meta($row->ID,'photo',true); $b_suburb = get_post_meta($row->ID,'suburb',true); $b_state = get_post_meta($row->ID,'state',true); $b_website = get_post_meta($row->ID,'website',true); echo '<option value="'.$row->ID.'" data-name="'.$b_name.'" data-photo="'.$b_photo.'" data-suburb="'.$b_suburb.'" data-state="'.$b_state.'" data-website="'.$b_website.'" >'.$b_name.'</option>'; } } ?> </select> </div> In this dropdown list posts value is already prompted.(在此下拉列表中,已提示输入值。) But i want post name as a selected option value.(但我想将职位名称作为选定的选项值。) I hope you understand my question.(我希望你能理解我的问题。) Thanks(谢谢)   ask by Nicks9789 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use method $_GET for trasport value to other page then use selected method:(您可以使用$ _GET方法将值转移到其他页面,然后使用所选方法:)

<?php $value=$_GET['VALUE1'] $othervalue=$_GET['VALUE2'] echo '<option value="$value" selected>$othervalue</option> EDIT: All code, in the first page a use "/submit-review.php?valueid=$ID&valuename=$NAME" for trasport value to next page :(编辑:所有代码,在第一页中使用“ /submit-review.php?valueid=$ID&valuename=$NAME”将值转移到下一页:) <h2 class="single-heading"> <?php echo get_the_title(); ?> Review <a href=" <?php echo home_url().'/submit-review.php?valueid=$ID&valuename=$NAME'; ?> " class="btn btn-light text-right pbd-title-btn" id="title" value=" <?php echo get_the_title($post->ID); ?> " > <i class="fa fa-plus" aria-hidden="true"> </i>Write a Review</a> </h2> And on the next page i will convert $_GET to the local variable for use it on selected box:(然后在下一页上,我将$ _GET转换为局部变量,以便在选定的框上使用它:) <div class="col-md-12 col-lg-12 col-xs-12 col-sm-12"> <label class="control-label">Select Breeder Name/Entity <span class="required">*</span></label> <select class="category form-control" data-placeholder="Select an option" id="pbd_review_name" name="pbd_review_name_id" > <?php $valueID= $_GET['valueid']; $valueNAME= $_GET['valuename']; echo "<option value='$valueID' selected>$valueNAME</option>"; $res = get_posts(array('post_type' => 'review', 'post_status' => 'publish', 'posts_per_page' => -1)); if(!empty($res)){ foreach($res as $row){ $b_name = $row->post_title; $b_photo = get_post_meta($row->ID,'photo',true); $b_suburb = get_post_meta($row->ID,'suburb',true); $b_state = get_post_meta($row->ID,'state',true); $b_website = get_post_meta($row->ID,'website',true); echo '<option value="'.$row->ID.'" data-name="'.$b_name.'" data-photo="'.$b_photo.'" data-suburb="'.$b_suburb.'" data-state="'.$b_state.'" data-website="'.$b_website.'" >'.$b_name.'</option>'; } } ?> </select> edit 3:(编辑3:) use SESSION for resolve your problem(first page):(使用SESSION解决您的问题(第一页):) <h2 class="single-heading"> <?php echo get_the_title(); ?> Review <a href=" <?php echo home_url().'/submit-review/'; ?> " class="btn btn-light text-right pbd-title-btn" id="title" value=" <?php echo get_the_title($post->ID); ?> " > <i class="fa fa-plus" aria-hidden="true"> </i>Write a Review</a> </h2> $_SESSION['id'] = $post->ID; $_SESSION['title'] = $post->title; On the second page:(在第二页上:) <div class="col-md-12 col-lg-12 col-xs-12 col-sm-12"> <label class="control-label">Select Breeder Name/Entity <span class="required">*</span></label> <select class="category form-control" data-placeholder="Select an option" id="pbd_review_name" name="pbd_review_name_id" > <?php $valueID= $_SESSION['id']; $valueNAME= $_SESSION['title']; echo "<option value='$valueID' selected>$valueNAME</option>"; $res = get_posts(array('post_type' => 'review', 'post_status' => 'publish', 'posts_per_page' => -1)); if(!empty($res)){ foreach($res as $row){ $b_name = $row->post_title; $b_photo = get_post_meta($row->ID,'photo',true); $b_suburb = get_post_meta($row->ID,'suburb',true); $b_state = get_post_meta($row->ID,'state',true); $b_website = get_post_meta($row->ID,'website',true); echo '<option value="'.$row->ID.'" data-name="'.$b_name.'" data-photo="'.$b_photo.'" data-suburb="'.$b_suburb.'" data-state="'.$b_state.'" data-website="'.$b_website.'" >'.$b_name.'</option>'; } } ?> </select>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...