• Hello,

    I want to have a searchform on my website.
    I added this code to a page on my website, but it doesn’t work.
    Can somebody help me?

    Thanks

    
    <form action="" method="post" id="pt-searchForm" class="pt-searchForm">
    <h3><i class="fa fa-search" aria-hidden="true">
    <div class="clearfix"></div>
    	<select name="category" class="form-control" onchange="this.form.action=this.options[this.selectedIndex].value;">
    		<option value="tickets/">Selecteer competitie</option>
    		<option value="dui">Duitsland</option>
    		<option value="eng">Engeland</option>
    		<option value="spa">Spanje</option>
    	</select>
    	<select name="choices" id="choices" class="form-control">
    		<option value="tickets/">Selecteer club</option>
    		<option value="tickets/engeland/manchester-united/">Manchester United</option>
    		<option value="tickets/engeland/manchester-city/">Manchester City</option>
    		<option value="tickets/engeland/arsenal/">Arsenal</option>
    		<option value="tickets/engeland/liverpool/">Liverpool FC</option>
    		<option value="tickets/engeland/chelsea/">Chelsea</option>
    		<option value="tickets/engeland/tottenham-hotspur/">Tottenham Hotspur</option>	
    		<option value="tickets/engeland/southampton/">Southampton</option>
    		<option value="tickets/duitsland/bayern-munchen/">Bayern München</option>
    		<option value="tickets/duitsland/borussia-dortmund/">Borussia Dortmund</option>
    		<option value="tickets/duitsland/hertha-berlin/">Hertha BSC</option>
    		<option value="tickets/duitsland/borussia-monchengladbach/">Borussia Mönchengladbach</option>
    		<option value="tickets/spanje/fc-barcelona/">FC Barcelona</option>
    		<option value="tickets/spanje/real-madrid/">Real Madrid</option>
    		<option value="tickets/spanje/valencia/">Valencia</option>
    		<option value="tickets/spanje/atletico-madrid/">Atlético Madrid</option>
    		<option value="tickets/spanje/sevilla/">Sevilla</option>
    	</select>
    	<input value="Zoek" class="btn btn-primary btn-branche" type="submit">
    	<div style="text-align: center; margin: 15px 0 0 0;">
    
    	</div>
    </form>
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    Your form’s action attribute is empty, so the form submittal will go to the current page. Does the page this form appears on have code to handle the form submit? If not, the action attribute must lead to code that does handle the submittal.

    Thread Starter ven2000

    (@ven2000)

    Thanks for your answer. The page have no code to handle the form submit. What code do I have to use to handle the submittal?

    Thanks

    Moderator bcworkz

    (@bcworkz)

    That’s a very broad question! I can give you some WP specific pointers, but for the rest of it, just search the ‘net for “PHP form handling” or similar. There will be plenty of generic tutorials you can use.

    You’ll be modifying the page’s template. If the form is on a single page, it should have its own custom template. It’s useful to place form handling code within a conditional structure based on $_SERVER[‘REQUEST_METHOD’] so the form handling code only executes for POST requests. You’ll need to do some or all security and sanitation procedures on the submitted data. All the form data is available in the $_POST array. After the needed security, validating, and sanitizing checks, do whatever is needed to be done with the data.

    In the case of search criteria, construct a new WP_Query object based on the search criteria. Loop through the returned posts as one normally would to display search results.

    Thread Starter ven2000

    (@ven2000)

    Thanks for your help. But this is too difficult for me. I’m just a beginner in coding.
    Perhaps you know somebody who can do this for me?

    Thanks.

    Moderator bcworkz

    (@bcworkz)

    Soliciting or offering coding help for compensation is contrary to the forum guidelines because such requests seem to draw out sleazy sorts who are seeking to take advantage of well meaning people like yourself. For your own protection please ignore any offers of paid help that might show up here.

    Thus I cannot recommend anybody specific, but you can find qualified help at jobs.wordpress.net or jetpack.pro. It shouldn’t be too expensive. The code required is pretty straight forward for a pro. You are probably right that it’s too much for a beginner.

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

The topic ‘Add a searchform’ is closed to new replies.