I'm trying to set it up so I can include one of my PHP files based on a dropdown selection. I found another answer on here that appears to do that but when I try it I get an error "undefined function".
The original answer is here Original
Here is my code:
<?php
$includes=array(
'phpfile1'=>'phpfile1.php',
'phpfile2'=>'phpfile2.php'
);
if(isset($_POST['cmtype']) && array_key_exists($_POST['cmtype'], $includes)) :
get_template_part($includes[$_POST['cmtype']]);
endif;
?>
<form id="selection_form" action="" method="post">
<select name="cmtype" id="cmtype">
<option value="default"> </option>
<option value="phpfile1">PHP file 1</option>
<option value="phpfile2">PHP File 2</option>
</select>
<input type="submit" name="select_mode_submit" value="Get File">
</form>
When I select either of the options and hit the button I get the error for 'get_template_part'. I assume it has something to do with the function being in the IF statement but I'm not sure how to fix it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…