I have the following set up below.
My issue is I'm not sure how to convert an inline echo $_GET
. Is it just the same as {{ fn( echo $_GET['units'] === 'Miles' ? 'selected' : null ) }}
??
<form method="get" action="{{ post.link }}">
<div>
<span>Find a Store within</span>
<input name="proximity" type="number" placeholder="15" value="<?php echo $_GET['proximity'] ?>" />
<select name="units">
<option value="Miles" <?php echo $_GET['units'] === 'Miles' ? 'selected' : null; ?>>Miles</option>
<option value="K" <?php echo $_GET['units'] === 'K' ? 'selected' : null; ?>>Km</option>
</select>
<span>from</span>
<input name="origin" type="text" placeholder="Your Address" value="<?php echo $_GET['origin'] ?>" />
</div>
<div>
<input type="submit" value="Search" />
<a href="{{ post.link }}">Reset</a>
</div>
</form>
Thanks to @DarkBee for pointing the above out: Passing PHP global variables via Twig/Timber
To access $_POST variables, use this:
To access $_GET variables, use this:
So that would make this:
Be this: