• I’m new to WordPress but fairly ok with php. I want to select an item from a dropdown list of Titles and send it to another page for processing with if(isset($Post[‘title’]) etc.
    However when I select an item title from the dropdown and hit send, it takes me to the actual page of that title itself with links forward and back to all the other pages in the Title list.
    I’ve tried a few things like attempting to make a string of the selected Title, and getting the list using get_post_meta(), but the end result is always the same as above.
    If anyone can just point me in the right direction that would be fantastic.

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    <form action="<?php bloginfo('url'); ?>/booking-times" method="post">
    <div class="style">
    		<select class="style" id="style" name="style">
    		<option value="" selected="selected">Select preferred style</option>
    
    		<?php
    		$args = array(
    			'post_type' => 'style',
    			'meta_key' => 'style_type',
    			'orderby' => 'menu_order',
    			'order' => 'ASC',
    			'post_status' => 'publish'
    		);
    		$style_listing= new WP_Query( $args ); ?>
    <?php if ( $style_listing->have_posts() ) : ?>
    			<?php while ( $style_listing->have_posts() ) : $style_listing->the_post(); ?>
    				<option id="<?php the_id(); ?>" class="style"  value=" <?php the_title(); ?>"><?php the_title(); ?></option>
    			<?php endwhile; ?>
    		<?php endif; ?>
    
    		</select>
    		</div><!--end div class style-->
    					</div><!--end div id style-->
    
    							<div id="submit">
    								<input class="data-submit" type="submit" name="submit" value="Next">
    							</div><!--end submit-->
    							</form>
Viewing 4 replies - 1 through 4 (of 4 total)
  • What are you trying to achieve is not clear here.

    According to the code it always sends the form data to the page yourwebsite.com/booking-times after the button Next is pressed I dont see any send button there too

    Thread Starter oldcrusty

    (@oldcrusty)

    Thank you very much Sakar for your reply. Sorry for not being clear. I have a booking form for a hair styling salon with inputs for selecting a date and a style-title. Using just plain php (without wordpress) it’s simple to send the inputs to another page (booking_times.php) where the date, and style-title values can be collected eg:-

    if(isset($_POST['submit'])) {
    	$style = $_POST['style-title'];
    }

    I’m trying to attempt the very same thing in a wordpress site. In my wordpress version of the same site the date will pass through to the booking_times.php page exactly the same as in a php only site but the selected style from the style dropdown list does not, instead it goes to
    the page with the Title of style-title.
    I’m basically trying to convert a php only site to a wordpress site and I’m at a bit of a loss as to where I need to do some research next.

    Moderator bcworkz

    (@bcworkz)

    For the style title and date to both be sent to a WP page, the fields need to be within the same form. I’m only seeing the style-title field in your form, no date.

    With WordPress, you can request PHP pages directly like booking_times.php, but that page cannot use any WP functions because the page either is not initializing the WP environment, or it is doing it wrong. There’s a limited number of ways to request code be run in the WP environment. This article explains:
    https://glennmessersmith.com/pages/wpenviro.html

    Thread Starter oldcrusty

    (@oldcrusty)

    Thank you very much bcworkz for that usefull info. Looks like I have some digging to do, but it’s the best way to learn.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Require selected dropdown list title-name as variable’ is closed to new replies.