我有这段代码可以打印从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;
?>
此链接http://z4site.com/social/pay/summary.php
中可能的xml响应<campaigns>
<campaign>
<vertical_name>Free Stuff</vertical_name>
<clicks>6</clicks>
<conversions>1</conversions>
</campaign>
</campaigns>
但我需要创建一个表单,让用户在使用ajax生成结果之前手动输入这些字段。
来自这段
$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>
答案 0 :(得分: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>