I have http://communitychessclub.com/test.php
I have a php function named "getPosts" that I want to send an url to from a form:
<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. 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
<?php
if(isset($_POST["url")){
$url = $_POST["url"];
}
else{
$url = "http://www.theweekinchess.com/twic-rss-feed";
}
getPosts($url); ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.