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?
$_POST["search"]is set?searchoption 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 inesc_url( home_url( '/local-concert-listings/' ) )?searchis sent via POST? and when I passesc_url( home_url( '/local-concert-listings/' ) )it breaks the code