0

I'm trying to pass a variable ($homezip) to the URL on a new page using add_query_arg(), but it's not working for variables although radius works fine.

$homezip = $_POST["search"];
$stringzip = esc_url( add_query_arg(
  array(
    'zip' => $homezip,
    'radius' => '70'
  ),'' ));


<form action="/local-concert-listings/<?php echo $stringzip; ?>" method="post">
      <input  id="address" size="5" type="text" placeholder="Zipcode" name="search"/>
      <input type="submit" value="go" name="SubmitButton" onclick="codeAddress()" />
</form> 

I've been trying to turn $homezip into a string but nothing works. What am I doing wrong here?

5
  • The code works fine. Are you sure that $_POST["search"] is set? Commented May 6, 2015 at 16:57
  • Also: codex.wordpress.org/Template_Tags/get_search_query Commented May 6, 2015 at 16:58
  • What do you mean by 'set'? Commented May 6, 2015 at 16:59
  • 1
    If the page is loaded and a search option is not sent via POST or if it's empty then your code will not do what you expect it to. You need to do validation. Also I wouldn't pass in '' as your url, would it not be better to pass in esc_url( home_url( '/local-concert-listings/' ) )? Commented May 6, 2015 at 17:01
  • How do I check to see if search is sent via POST? and when I pass esc_url( home_url( '/local-concert-listings/' ) ) it breaks the code Commented May 6, 2015 at 17:16

1 Answer 1

0

I ended up using a GET method and got rid of add_query_arg() function

$homezip = $_GET["search"];
<form action="local-concert-listings/" method="get">
        <input  id="address" size="6" type="text" placeholder="Zipcode" name="zipcode"/>
         <div style="display:none;">
         <input id="volume" size="1" name="miles" value="70" placeholder="70"></input>
              </div>      
         <input type="submit" value="go" name="SubmitButton" onclick="codeAddress()" />
 </form>  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.