页面加载onclick按钮

时间:2018-03-20 05:11:42

标签: php api aweber

我尝试了许多像window.stop这样的东西,但是不会工作并尝试在这段代码中创建一些函数但是再次失败了。

这是我的按钮

<input type="button" value="Click Me">

<?php

require_once('aweber_api/aweber_api.php');

// <!-- // Replace with the keys of your application
// // NEVER SHARE OR DISTRIBUTE YOUR APPLICATIONS'S KEYS! -->


$consumerKey    = "aaaa";
$consumerSecret = "bbbbb";

$aweber = new AWeberAPI($consumerKey, $consumerSecret);

if (empty($_COOKIE['accessToken'])) 
{
    if (empty($_GET['oauth_token'])) {
        $callbackUrl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        list($requestToken, $requestTokenSecret) = $aweber->getRequestToken($callbackUrl);
        setcookie('requestTokenSecret', $requestTokenSecret);
        setcookie('callbackUrl', $callbackUrl);
        header("Location: {$aweber->getAuthorizeUrl()}");
        exit();
    }

    $aweber->user->tokenSecret = $_COOKIE['requestTokenSecret'];
    $aweber->user->requestToken = $_GET['oauth_token'];
    $aweber->user->verifier = $_GET['oauth_verifier'];
    list($accessToken, $accessTokenSecret) = $aweber->getAccessToken();
    setcookie('accessToken', $accessToken);
    setcookie('accessTokenSecret', $accessTokenSecret);
    header('Location: '.$_COOKIE['callbackUrl']);
    exit();
}

# set this to true to view the actual api request and response
$aweber->adapter->debug = false;

$account = $aweber->getAccount($_COOKIE['accessToken'], $_COOKIE['accessTokenSecret']);

?>

<!DOCTYPE html>
<html lang="en">
<head>
  <title>AWeber Test Application</title>
  <link type="text/css" rel="stylesheet" href="styles.css" />
<body>
<?php
foreach($account->lists as $offset => $list) {
?>
<h1>List: <?php echo $list->name; ?></h1>
<h3><?php echo $list->id; ?></h3>
<table>
  <tr>
    <th class="stat">Subject</th>
    <th class="value">Sent</th>
    <th class="value">Stats</th>
  </tr>
<?php
foreach($list->campaigns as $campaign) {
    if ($campaign->type == 'broadcast_campaign') {
?>
    <tr>
        <td class="stat"><em><?php echo $campaign->subject; ?></em></td>
        <td class="value"><?php echo date('F j, Y h:iA', strtotime($campaign->sent_at)); ?></td>
        <td class="value"><ul>
              <li><b>Opened:</b>  <?php echo $campaign->total_opens; ?></li>
              <li><b>Sent:</b>  <?php echo $campaign->total_sent; ?></li>
              <li><b>Clicked:</b>  <?php echo $campaign->total_clicks; ?></li>
            </ul>
        </td>
    <?php
    }
} ?>
</table>
<?php }
?>
<body>
</html>

这个页面带我去重定向aweber登录,但是我想要一个按钮,然后点击按钮带我到aweber的登录页面,然后在登录后将我重定向到同一页面。 任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您没有检查是否单击了按钮以及页面加载时脚本是否正在运行。您也可以检查您的请求,只有在POST时才能执行操作。根据您的代码:

<form method="POST">
    <input type="submit" name="myButton" value="Click Me">
</form>

<?php
    // Check if the request is post
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        // Check if the button is clicked
        if (isset($_POST['myButton'])) {
            // Your code here
        }
    }

    // Some other code here
?>