-1

我试图从表单中的 value="" 获取文本到 php 变量 $_POST['twitter'] 但我一直得到一个空白,如果我删除 isset,我会收到一个未定义的错误。

<?php
//$twitter=(isset($_POST['twitter']));
var_dump($_POST);
?>

<form method="post" action="">
        <input type="checkbox" name="twitter" value="My Posting Text">Would you like to send to Twitter?<br>
</form>

<div id="custom-tweet-button">
    <a href="https://twitter.com/share?" id="my_twitter_id" data-show-screen-name="false" data-url="https://nyctelecomm.com" data-text="<?php echo $_POST['twitter']; ?>" data-counturl="null" class="twitter-share-button" target="_blank" data-count="horizontal" data-lang="en" data-via="NYCTelecomm.com">Tweet</a>
</div>
    <script language="javascript" type='text/javascript'>
                !function (d, s, id)
                {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (!d.getElementById(id))
                    {
                        js = d.createElement(s);
                        js.id = id;
                        js.src = "//platform.twitter.com/widgets.js";
                        fjs.parentNode.insertBefore(js, fjs);
                    }
                }
                (document, "script", "twitter-wjs");
     </script>
4

1 回答 1

0

您需要确保您的表单正在提交。

试试这个:

<?php
    if(isset($_POST['submit_twitter'])) {
        // should set here
        $twitter=(isset($_POST['twitter']));

        var_dump($_POST);
    }
?>

<form method="post" action="">
        <input type="checkbox" name="twitter" value="My Posting Text">Would you like to send to Twitter?<br>
        <input type="submit" name="submit_twitter" value="Submit">
</form>


<?php
    // This will only show if $twitter has been set with the post data
    if(isset($twitter)) :
?>
<div id="custom-tweet-button">
    <a href="https://twitter.com/share?" id="my_twitter_id" data-show-screen-name="false" data-url="https://nyctelecomm.com" data-text="<?php echo $_POST['twitter']; ?>" data-counturl="null" class="twitter-share-button" target="_blank" data-count="horizontal" data-lang="en" data-via="NYCTelecomm.com">Tweet</a>
</div>
    <script language="javascript" type='text/javascript'>
                !function (d, s, id)
                {
                    var js, fjs = d.getElementsByTagName(s)[0];
                    if (!d.getElementById(id))
                    {
                        js = d.createElement(s);
                        js.id = id;
                        js.src = "//platform.twitter.com/widgets.js";
                        fjs.parentNode.insertBefore(js, fjs);
                    }
                }
                (document, "script", "twitter-wjs");
     </script>

<?php 
    endif;
?>
于 2013-11-13T01:57:23.247 回答