dtd58256 2015-05-11 10:29
浏览 30
已采纳

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

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); ?>
  • 写回答

1条回答 默认 最新

  • dpcnm2132 2015-05-11 10:42
    关注

    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); ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备