我試圖設置它,所以我可以包括我的一個PHP文件基於下拉選擇。我在這裏找到另一個答案,似乎這樣做,但當我嘗試它時,我得到一個錯誤「未定義函數」。包含基於下拉選擇的PHP文件
原來答案就在這裏Original
這裏是我的代碼:
<?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>
當我選擇的選項,並按下按鈕,我得到的錯誤「get_template_part」。我認爲它與IF語句中的函數有關,但我不知道如何解決它。
get_template_part()定義在哪裏? – markdwhite
完整的錯誤將是有用的 –
你甚至有一個文件,該函數'get_template_part'? –