• Resolved btees

    (@btees)


    Hi guys,

    I’m trying to put together a custom search form based on your search widget, it’ll be just below the header and I intend for it to be all dropdowns.

    The only problem I’m having is that when I run the search, the dropdowns return to their default position.

    I’ve been fiddling with this all day, so any advice would be greatly appreciated.

    Here’s my code, please forgive any sloppiness, I’ve been at it so long, I’m zombified tired!

    <div id="propertysearch">
    <section id="searchpropertieswidget-4" class="widget wpp_property_attributes"><div class="wpp_search_properties_widget"><span class="wpp_widget_no_title"></span>
    
        <?php
        if($_POST["submit"]) {
            $name_title = $_POST["wpp_search[property_type]"];
            }
    
    ?>
    
    <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" class="wpp_shortcode_search_form">
                                    <input type="hidden" name="wpp_search[pagination]" value="off">
                              <input type="hidden" name="wpp_search[strict_search]" value="false">
                      <ul class="wpp_search_elements">
              <li class="wpp_search_group wpp_group_not_a_group">
                  <ul class="wpp_search_group wpp_group_not_a_group">
                  <li for="wpp_search_element_4963" class="typemargin wpp_search_label wpp_search_label_property_type">Type<span class="wpp_search_post_label_colon">:</span>
    <li class="wpp_search_form_element seach_attribute_property_type  wpp_search_attribute_type_property_type ">
              <div class="wpp_search_attribute_wrap">
    <select id="wpp_search_element_6302" class="wpp_search_select_field wpp_search_select_field_property_type property_type" name="wpp_search[property_type]">
            <?php
        $names = array(
        '' => 'Any',
        'house_rental' => 'House (rental)',
        'apartment_rental' => 'Apartment (rental)',
    );
    
    foreach ($names as $key => $name) {
    
     $selection = ($key === $name_title) ? 'selected="selected"' : '';
    
            echo '\t<option value="' . $key . '" ' . $selection. '> ' . $name . '</option>';
    
        }
    
    ?>
     ?>
    </select>
    
                        </div>

    https://www.ads-software.com/plugins/client-dash/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter btees

    (@btees)

    Here is my updated code:

    <?PHP
    $name_title = $_POST["wpp_search[property_type]"];
        if($_POST["submit"]) {
            $name_title = $_POST["wpp_search[property_type]"];
    
            //Check the name title that it is selected or none.
                    if($name_title === none){
                        //if selected is none, add error to $errors array.
                        $errors['name_title'] = "Please select the title of your name!";
                    }
    
            // sending form
            if(empty($errors)){
                $mail_sent = wp_mail( $to, $subject, $mailBody, $headers );
            }       
    
        }
        if ($mail_sent) {
    ?>
    
    <h1 style="color: #007f00;">Request sent.</h1>
    
    <?php
    } else {
    ?>
    <div id="propertysearch">
    <section id="searchpropertieswidget-4" class="widget wpp_property_attributes"><div class="wpp_search_properties_widget"><span class="wpp_widget_no_title"></span>
    
    <form id="" name="" action="<?php echo get_permalink(); ?>" method="post">
        <div class="label-input-wrapper">
        	<ul class="wpp_search_elements">
            <li><div class="form-label">Title</div></li>
            <div class="form-input">
                <li><select id="wpp_search_element_6302"
    		class="wpp_search_select_field wpp_search_select_field_property_type property_type"
    		name="wpp_search[property_type]">
    	<?php
    		$names = array(
    			'' => 'Any',
    			'house_rental' => 'House (rental)',
    			'apartment_rental' => 'Apartment (rental)',
    		);
    		foreach ($names as $key => $name)
    		{
    			$selection = ($key === $name_title) ? 'selected="selected"' : '';
    			echo '\t<option value="' . $key . '" ' . $selection. '> ' . $name . '</option>';
    		}
    	?>
     ?>
     </select>
     </li>
    
       <li class="wpp_search_form_element submit"><input type="submit" class=" searchmargin wpp_search_button submit btn btn-large" value="Search"></li>
        </ul>
        </div>
        </div>
    </form>
    </section>
    </div>
    <?php
    }
    ?>

    It seems the problem is specifically that the select name has square brackets in it, so my $name_title = $_POST[“”] isn’t reading it. If I change that to something without square brackets the dropdown remains filled as desired, but of course doesn’t do the search then.

    Does anyone know if it’s possible to:

    a) wrap the name in such a way that my $name_title = $_POST[“”] can read it

    or

    b) Change the name of the select within the plugin to something I choose, so it activates the search on my select name

    ?

    Many thanks for any input!

    Thread Starter btees

    (@btees)

    Apologies guys, I was obviously way more tired than I though, this request for for an entirely different plugin. I have no idea how this got here!

    Plugin Contributor joelworsham

    (@joelworsham)

    Ha! Okay. No worries. I was just about to look into this.

    Been zombified far too may times myself ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom search (and keeping dropdown inputs)’ is closed to new replies.