dongtun2572 2012-03-07 14:40
浏览 43
已采纳

使用magento安全网址进行操作时,表单提交无效

I have a from that when submit runs a little php to export data to a csv. The php looks like :

$out = '';
if (isset($_POST['csv_hdr'])) {
$out .= $_POST['csv_hdr'];
$out .= "
";
}

if (isset($_POST['csv_text'])) {
$out .= $_POST['csv_text'];
}

$filename = "z_".date("Y-n-d",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-n-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $out;
exit;

This works fine if I do a normal path to the php file like :

<form name="export"  action="http://website.com/getcsv.php"  method="post"> 

I am trying to move this php function into a controller now and call it that way. I am working on a magento admin module so I have to pass the url with the security key. So I move that function into an action in the controller :

public function getcsvAction(){
    $out = '';
    ...
}

Then I am able to get the url with something like :

<?php echo Mage::helper("adminhtml")->getUrl("module/index/getcsv/");?>

This gives me a link with the key like :

http://website.com/module/index/getcsv/key/7431c859914c40d3f66dfcd1530813b3/

If I paste that link into the browser it executes the php fine. However when I replace it in my form action it no longer works and just does a redirect to the dashboard. I can not see any errors output and I am not sure what is happening. Any ideas on how to get this POST to work using a secure path as the action?

  • 写回答

2条回答 默认 最新

  • dongtan3395 2012-03-07 16:22
    关注

    I found it thanks to this post.

    I needed to add this to the form :

    <input type="hidden" name="form_key" value="<? echo $this->getFormKey(); ?>" /> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题