简体   繁体   English

php不会将变量传递给php rss函数

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

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

I have a php function named "getPosts" that I want to send an url to from a form: 我有一个名为“ 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>

For some reason, the php code below doesn't grab the option selected and pass it to the function. 由于某些原因,下面的php代码没有获取所选的选项,并将其传递给函数。 Why is that? 这是为什么?

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

getPosts($url); ?>

its because there is no submit button. 这是因为没有提交按钮。 if you want to auto-submit form on change you need to do something like 如果您想在更改时自动提交表单,则需要执行以下操作

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

I just checked and it looks it works fine. 我刚刚检查了一下,看来效果很好。

Also you don't really need $sub thing, you can just do 而且你真的不需要$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