0

我有这段代码可以打印从 API xml 中提取的某些结果

 <?php
  echo "<h1>Approval Stats</h1><br /><br />"; 
      echo "Report for Agent Name: <b>Bhaskar</b><br />"; 

 $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_VERBOSE, 0);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
   curl_setopt($ch, CURLOPT_POST, true);
   curl_setopt($ch, CURLOPT_URL,'http://login.leadkitchen.com/affiliates/api/4/reports.asmx/CampaignSummary' );



 $post_array = array(
         'api_key' => 'abc',
         'affiliate_id' => 'abc',
        'start_date' => '10/8/2012',
       'end_date' => '10/11/2012',
       'sub_affiliate' => 'email',
     'start_at_row' => '1',
        'row_limit' => '0',
     'sort_field' => 'offer_name',
     'sort_descending' => 'true'
      );

      //url-ify the data
      foreach($post_array as $key=>$value) 
     { 
          $post_array_string .= $key.'='.$value.'&'; 
      }
      $post_array_string = rtrim($post_array_string,'&');
      //set the url, number of POST vars, POST data
      curl_setopt($ch,CURLOPT_POST,count($post_array ));
      curl_setopt($ch,CURLOPT_POSTFIELDS,$post_array_string);
      $response = curl_exec($ch);
     // print_r($response);

    $xml = new SimpleXMLElement($response);
    echo "<pre>";
    echo "Process Name: "; echo $xml->campaigns->campaign->vertical_name, PHP_EOL;
    echo "Approvals: "; echo $xml->campaigns->campaign->conversions, PHP_EOL;
    echo "Applied: "; echo $xml->campaigns->campaign->clicks, PHP_EOL;




?>

此链接中可能的 xml 响应http://z4site.com/social/pay/summary.php

<campaigns>
<campaign>

<vertical_name>Free Stuff</vertical_name>

<clicks>6</clicks>
<conversions>1</conversions>

</campaign>
</campaigns>

但我需要创建一个表单,让用户在使用 ajax 生成结果之前手动输入这些字段。

  1. sub_affiliate
  2. 开始日期
  3. 结束日期

从这个段落

 $post_array = array(
     'api_key' => 'abc',
     'affiliate_id' => 'abc',
    'start_date' => '10/8/2012',
   'end_date' => '10/11/2012',
   'sub_affiliate' => 'email',
 'start_at_row' => '1',
    'row_limit' => '0',
 'sort_field' => 'offer_name',
 'sort_descending' => 'true'
  );

我该怎么做..我应该为此创建一个 HTML 文件吗?你能建议我的代码吗?谢谢

html 文件http://z4site.com/social/pay/report.html

<html>
<head>

</head>
<body>
<form method="post" action="summary.php">
<input type="text" name="sub_affiliate" />
<input type="text" name="start_date" />
<input type="text" name="end_date" />
<input type="submit" name="submit" value="Search" />
</form>

</body>
</html>
4

1 回答 1

0

这是基本的 HTML+PHP 交互。您可以使用以下代码来检查以确保他们已提交具有有效输入的表单,这样您就不会在 API 上执行获取代码,直到他们这样做。

if(!empty($_POST['sub_affiliate'])&&!empty($_POST['start_date'])&&!empty($_POST['end_date'])){//do stuff}

在下面的 HTML 中,您可以使用一个简单的表单:

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="text" name="sub_affiliate" />
    <input type="text" name="start_date" />
    <input type="text" name="end_date" />
    <input type="submit" name="submit" value="Search" />
</form>
于 2012-10-11T17:14:44.200 回答