Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
207 views
in Technique[技术] by (71.8m points)

Include PHP file based on Dropdown Selection

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
`get_template_part() 

is WordPress built in function and is not PHP built in function. There may be a problem with you WordPress installation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...