2013-04-11 40 views
1

这被问到literally two weeks ago,我很抱歉,但我必须做错了什么。

我有:

<form action="action.php"> 
    <input type="text" name="bar" /> 
    <input type="submit" name="submit" value="Go!" /> 
</form> 

,并在相应action.php的,

<script type='text/php'> 
    $test = $_GET['bar']; 

    if ($_GET['submit']) { 
     $message = 'OK'; 

    } 

    else { 
     $message = 'No'; 
    } 

</script> 

<script> 
    document.write(test); 
    document.write(message); 
</script> 

的结果是"Null""No" - $_GET['bar']被解释为empty(当它不是),甚至$_GET['submit']甚至不会返回true(当我通过单击'submit'按钮到达页面时)。

这是究竟是solution given概述的实现....对吧?

这是否不再适用于TideSDK?我在这里错过了什么?如果这无法在PHP & TideSDK中完成,那么我最好的方法是将计算或用户输入的参数从一个页面传递到另一个页面?感谢大家。

[注 - 我复制/粘贴的代码,所以一些遗漏/矛盾现在应该消失。对不起!]

+0

使用'

1

您将需要在表单中给予foo作为字段,并给提交按钮一个名称。可能通过更改您的表单会给你想要的结果。

<form action="action.php" method="get"> 
     <input type="text" name="foo" value="1234" /> 
     <input type="text" name="bar" /> 
     <input name="submit" type="submit" value="Go!" /> 
    </form> 

在PHP中,你需要这样写:

<?php 
$test = $_GET['bar']; 


if ($_GET['submit']) { 
    $message = 'OK'; 

} 

else { 
    $message = 'No'; 
    } 


    echo $test; 
    echo $message; 
?> 

我不知道PHP的安装在你的地方或没有。

如果你想使它在JavaScript中使用下面的一个:

<script> 
//$test = $_GET['bar']; 
function getParameterByName(name) 
{ 
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); 
    var regexS = "[\\?&]" + name + "=([^&#]*)"; 
    var regex = new RegExp(regexS); 
    var results = regex.exec(window.location.search); 
    if(results == null) 
    return ""; 
    else 
    return decodeURIComponent(results[1].replace(/\+/g, " ")); 
} 

if (getParameterByName("submit")) { 
    message = 'OK'; 

} 

else { 
    message = 'No'; 
    } 

</script> 
<script> 
    document.write(getParameterByName("foo")); 
    document.write(message); 
</script> 
+0

这里肯定是凌晨4点,哈哈。我在代码中要求'bar'而不是foo,但是无论如何,它仍然返回Null和No.我的问题是否不可重现? – 2013-04-11 11:27:24

0
<input type="submit" value="Go!" /> 

在哪里名为 “提交” 为$_GET['submit']

使用<input type="submit" name ="you" value="Go!" />
然后askfor$_GET['you']

它便于检查

if (isset($_GET['bar'])) 
{ 
    $message = 'OK'; 
} 
+0

哦,那是我的不好。我在那里有名称=“提交”。我在那里有几个拼写错误,应该只是复制/粘贴。 – 2013-04-11 11:25:52

+0

检查更新的答案 – 2013-04-11 11:31:54

+0

耶 - 检查isset不返回“确定”。这让我觉得这是TideSDK的一些怪癖,我不知道。尽管如此,感谢您的所有帮助! – 2013-04-11 11:38:13