If statement on $_REQUEST then do something.
2 posts by 2 authors in: Forums > CMS Builder
Last Post: January 17, 2020 (RSS)
By Mikey - January 16, 2020
Howdy folks,
I'm trying to create in if statement that will only display the last select option "All Floor Plans" if a prior selection exist, but I can't seem to get this figured out. Any suggestions on how to get this if statement to function are much appreciated.
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="floorplanResults">
<select name="floor_plan_match" onchange="$('#floorplanResults').submit();">
<option value="">Floor Plans</option>
<?php foreach ($homes_for_saleCatArray as $value => $label): ?>
<option value="<?php echo $value; ?>" <?php selectedIf($value, @$_REQUEST['floor_plan']) ?>><?php echo $label; ?></option>
<?php endforeach ?>
<?php if($_REQUEST['floor_plan'] === $value): ?><option value="">All Floor Plans</option><?php endif; ?>
</select>
</form>
Thanks, Zick
By daniel - January 17, 2020
Hi Zick,
I think this should accomplish your goal:
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>" id="floorplanResults">
<select name="floor_plan_match" onchange="$('#floorplanResults').submit();">
<option value="">Floor Plans</option>
<?php foreach ($homes_for_saleCatArray as $value => $label): ?>
<option value="<?php echo $value; ?>" <?php selectedIf($value, @$_REQUEST['floor_plan']) ?>><?php echo $label; ?></option>
<?php endforeach ?>
<?php if(!empty($_REQUEST['floor_plan'])): ?><option value="">All Floor Plans</option><?php endif; ?>
</select>
</form>
This will add the last option "All Floor Plans" to the dropdown if the $_REQUEST['floor_plan'] has any non-empty value in it.
Let me know if you have any further questions!
Thanks,
Technical Lead
interactivetools.com