簡體   English   中英

php不會將變量傳遞給php rss函數

[英]php won't pass variable to php rss function

我有http://communitychessclub.com/test.php

我有一個名為“ getPosts”的php函數,我想從表單發送一個URL:

<form action="#" method = "post"> 
<input type="hidden" name="sub" value="1" /> 
<select name="url" id="url">
<option value="http://www.chess.com/rss/articles">chess.com</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>

</select>
</form>

由於某些原因,下面的php代碼沒有獲取所選的選項,並將其傳遞給函數。 這是為什么?

<?php
$sub = intval( $_POST["sub"]);  
if ($sub == 1){ 
$url= $_POST["url"];
}
else{
$url = "http://www.theweekinchess.com/twic-rss-feed"; 
}

getPosts($url); ?>

這是因為沒有提交按鈕。 如果您想在更改時自動提交表單,則需要執行以下操作

<form name="myform" action="#" method = "post">
<select name="url" id="url" onchange="document.forms['myform'].submit()">

我剛剛檢查了一下,看來效果很好。

而且你真的不需要$sub東西,你可以做

<?php

if(isset($_POST["url")){
$url = $_POST["url"];
}
else{
$url = "http://www.theweekinchess.com/twic-rss-feed"; 
}

getPosts($url); ?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM