2013-05-09 79 views
0

我有一些代码会发布到用户墙上,但是,当它加载页面时会发布,我只需要发布帖子我的墙上按钮被提交。只有当提交按钮被按下时,才会发生动作

这里是我的代码:

<div align="center"> 
<form method="GET" action="translate.php"> 
<textarea name="status2" cols="50" rows="5"<input type="text"/> 
<?php echo str_ireplace(array  ('old','awkward','all','again','behind','along','alright','hello','among','children','yes','child','kids','food','barnard castle','beer','book','blow','beautiful','bird','burst','brown','burn','boots'), 
array ('auld', 'aakwad', 'aall','agyen','ahint','alang','alreet','alreet','amang','bairns','aye','bairn','bairns','bait','barney','beor','beuk','blaa','bonny','bord','borst','broon','bourn','byeuts'),$status); ?> 

</textarea><br> 

<input type="submit" value="post to wall" 
// i did try my wall code here but it still posted on page load 
/> 
</form> 

</div> 

<?php 

$args = array(
    'message' => 'Hello World', 
    'link'  => 'http://apps.facebook.com/geordie-status/', 
    'caption' => 'Translate from English to Geordie' 
    ); 
$post_id = $facebook->api("/$uid/feed", "post", $args); 

?> 

回答

1

name属性添加到您的input标记中。并使用isset来检查用户是否按下了提交按钮。

 <input type="submit" value="post to wall" name="submit" 
     // i did try my wall code here but it still posted on page load 
     /> 
     </form> 

</div> 

    <?php  
     if (isset($_POST['submit'])){ 
     $args = array(
      'message' => 'Hello World', 
      'link'  => 'http://apps.facebook.com/geordie-status/', 
      'caption' => 'Translate from English to Geordie' 
      ); 
     $post_id = $facebook->api("/$uid/feed", "post", $args); 
     } 
     ?> 
+0

lmao,我只是想出了这一点,但改变了形式行动post.php,并基本上增加了上述,如果到post.php。不管怎样,你仍然可以得到答案:D – 2013-05-09 21:10:39

0

你应该把代码张贴到里面translate.php墙,因为这是在表单操作中列出的页面。当表单被提交时,值将作为参数传递给translate.php,然后您可以使用$ _GET来获取它们并执行写入到墙上的代码。

+0

对不起,我应该提到,这段代码是在translate.php里面。我需要的是只有在点击提交按钮时才执行的PHP代码。在我弄清楚之后,我可以专注于我的其余问题。谢谢 – 2013-05-09 20:09:35

+0

那么你可以在表单中添加一个,然后检查$ _GET ['isSubmitted'] =='true',如果是的话,那么你知道表单提交按钮被实际点击并且数据被发布。 – 2013-05-09 20:49:48

0

我认为你的问题是你的浏览器每次页面重新加载时都会重新发送数据。

有2种方法:

  • 重定向用户到同一个页面,这样发送的数据将被清除(header("Location: asd")

  • 存储一些散在会议上,做一个隐藏的输入,并检查是否散列是正确的。正确提交表单时更改散列。

+0

不确定这是什么意思说实话。上面的代码是我的translate.php页面。在此之前,用户使用我的index.php,并使用POST将输入的数据发送到translate.php。 textarea用于在数据更改后显示数据,用户可以点击“提交”,以便将数据发布到墙上。 – 2013-05-09 20:14:14

相关问题