• 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 for two days, so any advice would be greatly appreciated.

    Here’s where my code’s at at the moment:

    <?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!

    https://wordpress.org/plugins/wp-property/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Maxim Peshkov

    (@maximpeshkov)

    Hello,

    I would suggest you to print your $_POST variable.

    The following code is absolutely incorrect:

    $_POST["wpp_search[property_type]"]

    It must be:

    $_POST['wpp_search']['property_type']

    Also, I’m not sure what you tried to achieve by the following condition:

    if( $name_title === none ) {
     // logic
    }

    But it’s invalid. I guess you wanted something like:

    if( empty( $name_title ) ) {
     // logic
    }

    Please, note, we are not supporting any customisation of WP-Property plugin here.
    It was the only exception.

    Regards.

    Thread Starter btees

    (@btees)

    Hi Maxim,

    Thanks for your time.

    I don’t expect you to give customisation advice, so I’ll understand if you don’t reply or whatever.

    But hopefully if I throw this out to the community someone will come up with something 🙂

    Here’s my code now:

    <?PHP
    $type = "hello";
    $name_title = $_POST['derp'];
        if($_POST['submit']) {
            $name_title = $_POST['derp'];
    ?>
    
    <?php
    } else {
    ?>
    <div id="propertysearch">
    	<div id="printit"><?php print_r($_POST ["wpp_search"]["property_type"]); ?></div>
    	<div id="printit2"><?php print_r($_POST ["derp"]); ?></div>
    <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="http://seoanseo.ie/property/listings/" 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>
    
    <input id="property_type" class="" name = "wpp_search[property_type]">
    <select id="demo" type="hidden" name="derp" onchange="myFunction()">
    	<?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>
    <script>
    function myFunction() {
        var x = document.getElementById("demo").value;
        document.getElementById("property_type").value = x;
    }
    </script>
     </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>
    
    <?php
    }
    ?>

    So I tried $_POST ["wpp_search"]["property_type"] which didn’t seem to work.

    Then I set up a duplicate field that fills in the same info, it’s name is derp and it’s id is demo.

    When I set up two divs to print the what is posted, nothing shows up in the divs on the search result page.

    If I comment out the field that goes through to wp properties search likes so:
    <!-- <input id="property_type" class="" name = "wpp_search[property_type]"> -->

    when the inputs post the value is printed on screen.

    Is it somehow not posting on the search results page?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom search (and keeping dropdown inputs)’ is closed to new replies.