以下是我想要包含在wordpress内容中的代码,并根据提交的值显示html文件。我需要做些什么来完成这项工作?我是wordpress的新手,所以任何帮助都会非常感激。我已经安装了一个php插件来与我的Wordpress网站一起工作。提前谢谢
<h3>Province:</h3>
<select name="province" >
<option value="A" >A</option>
<option value="B" >B</option>
<option value="C" >C</option>
<option value="D" >D</option>
<option value="E" >E</option>
</select>
<h3>Year:</h3>
<?php
$years = array();
for ($i = 2018; $i > 2012; $i--)
{
$years[] = $i;
}
echo "<select name='year'>";
foreach($years as $option){
echo "<option value='{$option}'>{$option}</option>";
}
echo "</select>";
?>
<h3>Month:</h3>
<select name="month" >
<option value="January" >January</option>
<option value="February" >February</option>
<option value="March" >March</option>
<option value="April" >April</option>
<option value="May" >May</option>
<option value="June" >June</option>
<option value="July" >July</option>
<option value="August" >August</option>
<option value="September" >September</option>
<option value="October" >October</option>
<option value="November" >November</option>
<option value="December" >December</option>
</select>
<div>
<input type="submit" name="submit" value="Submit" class="btnSubmit" />
</div>
</div>
<div >
<?php
if($_GET){
echo "<strong>".$_GET['province']." Price Monitoring as of ".$_GET['month']." ".$_GET['year']."</strong>"; }
?>
</div>
</form>
<div>
/*access file directory using submitted fields */
<?php
if($_GET){
echo '<embed src=wp-content/uploads/pricewatch/'.$_GET['province'].''.$_GET['month'].''.$_GET['year'].'.htm width="700" height="800"{ # code...}/>';
}
?>
</div>
答案 0 :(得分:0)
我的意思是,看起来你相对接近,看起来你的<embed>
标签看起来很混乱,因此无效。
请看一下这个链接:https://xhynk.com/KrutSednar.php
将Year
值保留为2018,因为我只创建2018.htm
如果我是你,我会使用 file_get_contents() 而不是<embed>
- 但是任何一种方法(甚至<iframe>
都可以用来提取HTML文件
我已经冒昧地清理了您的代码,但需要注意的主要内容是您可以用以下内容替换<embed>
行:
if( $_GET ) echo file_get_contents( '/wp-content/uploads/pricewatch/$province/$month/$year.htm' );
这是更新后的代码。几点说明:
<form>
所以我将此action
作为当前网址。$year
循环$months
变成了类似的循环。$_GET
)并将$_GET['year']
转换为$year
,这是$key => $val
循环的用途。.htm
文件的路径,我添加了斜杠,因为我认为它们已存在,但您可以根据需要修改该字符串。 / LI>
希望有意义!
<form action="<?= ( isset($_SERVER['HTTPS'] ) ? "https" : "http" ) . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; ?>">
<div>
<h3>Province:</h3>
<select name="province">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
</select>
<h3>Year:</h3>
<select name="year">
<?php for( $i = 2018; $i > 2012; --$i ) echo "<option value='$i'>$i</option>"; ?>
</select>
<h3>Month:</h3>
<select name="month">
<?php for( $m = 1; $m <= 12; ++$m ){
$month = date( 'F', mktime( 0, 0, 0, $m, 1 ) );
echo "<option value='$month'>$month</option>";
} ?>
</select>
<div>
<input type="submit" name="submit" value="Submit" class="btnSubmit" />
</div>
</div>
<div>
<?php
if( $_GET ){
foreach( $_GET as $key => $val ) ${$key} = $val;
echo "<strong>$province Price Monitoring as of $month $year</strong>";
}
?>
</div>
</form>
<div>
<?php
if( $_GET ) echo file_get_contents( '/wp-content/uploads/pricewatch/$province/$month/$year.htm' );
//if( $_GET ) echo "<embed src='/wp-content/uploads/pricewatch/$province/$month/$year.htm' width='700' height='800'";
?>
</div>