PHP - 在帖子提交时调用函数?

Currently have this:

<script>
  function copyToClipboard(info, text) {
    window.prompt(info, text);
  }
</script>

<?php
    function getLink($user) {
      return '<a class="clicky" onclick="copyToClipboard(
                \'Copy to clipboard: Ctrl+C, Enter
Use this on any forum with [img] tags!\', 
                \'site/pcard.php?user='.$user.'\');">
                <span class="label label-primary">Get Link</span>
              </a>';
    }
?>

<div class="well">
    <form method="post">
        <label>Get Signature Image</label>
        <input type="text" placeholder="Username..." name="signame" />

        <button type="submit" class="btn btn-primary">Look-up</button>
<?php
if (isset($_POST)) {
  getLink($_POST['signame']);
}
?>
    </form>

How would I go on to make this call that script with the posted info? Also, are there any other mistakes here?

Noticed 2 things:

  1. $_POST is always there. So isset($_POST) is always true. You should check the existence of parameter within it (e.g. $_POST['signme']) or check if its not empty (e.g. !empty($_POST)).

  2. The getLink function doesn't really print the result out itself. It just returning the HTML string that you just ignored. You should print the returns of getLink.

I think this is what you needed:

    <script>
      function copyToClipboard(info, text) {
        window.prompt(info, text);
      }
    </script>

    <?php
        function getLink($user) {
          return '<a class="clicky" onclick="copyToClipboard(
                    \'Copy to clipboard: Ctrl+C, Enter
Use this on any forum with [img] tags!\', 
                    \'site/pcard.php?user='.$user.'\');">
                    <span class="label label-primary">Get Link</span>
                  </a>';
        }
    ?>

    <div class="well">
        <form method="post">
            <label>Get Signature Image</label>
            <input type="text" placeholder="Username..." name="signame" />

            <button type="submit" class="btn btn-primary">Look-up</button>
    <?php
    if (isset($_POST['signame'])) {
      print getLink($_POST['signame']);
    }
    ?>
        </form>
    </div>