如何向php rss feed脚本添加表单选择选项

时间:2015-05-11 08:29:26

标签: php rss

我正在尝试将一个下拉列表添加到RSS提要解析器。

我有这个:

<fieldset class="rsslib">

<?php
$cachename = "rss-cache-tmp.php";
$url = "http://www.theweekinchess.com/twic-rss-feed"; 

if(file_exists($cachename))
{
    $now = date("G");
    $time = date("G", filemtime($cachename));
    if($time == $now)
    {
        include($cachename);
        exit();
    }
}
require_once("rsslib.php");
$cache = RSS_Display($url, 15, false, true);
file_put_contents($cachename, $cache);
echo $cache;
?>
</fieldset>

但是我想在php中使用select选项设置$ url:

<?php

$temp = $_POST["url"];

?>

<form method = "post">  
<select name="url" id="url">
<option value="http://www.theweekinchess.com/twic-rss-feed">TWIC</option>
<option value="http://chesscafe.com/feed/">Chess Cafe</option>
<option value="http://www.chessdom.com/rss">Chessdom</option>
<option value="http://chess-news.ru/rss-eng">Chess-news</option>
<option value="http://www.chess.com/rss/articles">chess.com</option>
</select>
</form>

但是我无法将表单变量传递给php脚本。我试过,但我的结果很可怜,我想留下原始代码来简化事情。

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您的表单需要采取行动。

您需要知道表单是否已提交:($ sub)

<?php
$sub = intval( $_POST["sub"]);  
if ($sub == 1){ 
  $url= $_POST["url"];
}
else{
  $url = "http://www.theweekinchess.com/twic-rss-feed"; 
}
require_once("rsslib.php");
$cache = RSS_Display($url, 15, false, true);
$cachename = "rss-cache-tmp.php";
file_put_contents($cachename, $cache);



// I have no idea what you are doing here or why

if(file_exists($cachename)){
  $now = date("G");
  $time = date("G", filemtime($cachename));
  if($time == $now){
    include($cachename);
    exit();
  }
}


echo <<<EOT
$cache;
<fieldset class="rsslib">  // ??????

</fieldset>
<form action="#" method = "post"> 
<input type="hidden" name="sub" value="1" /> 
<select name="url" id="url">
<option value="http://www.theweekinchess.com/twic-rss-feed">TWIC</option>
<option value="http://chesscafe.com/feed/">Chess Cafe</option>
<option value="http://www.chessdom.com/rss">Chessdom</option>
<option value="http://chess-news.ru/rss-eng">Chess-news</option>
<option value="http://www.chess.com/rss/articles">chess.com</option>
</select>
</form>
EOT;
?>