dotcraq3249 2013-06-26 22:50
浏览 12

如何不将提交按钮值存储为发布数据php

ok i have dynamically created form elements with unique names and when validated i want to store all the form data into SESSION. This is the code to do it:

if(isset($_POST["address_submit"])){
  insertSessionVars();
  header("Location: http://localhost/project%20gallery/notes.php");
  exit;
}

function insertSessionVars(){
  foreach($_POST as $fieldname => $fieldvalue){
    $_SESSION['formAddresses'][$fieldname] = $fieldvalue;
  }
}

This works almost fine but stores also submit button value. I output it like this:

foreach($_SESSION['formAddresses'] as $value){

    echo $value;

}

Any help will be greatful :)

  • 写回答

3条回答 默认 最新

  • dpu66046 2013-06-26 22:52
    关注

    Don't assign a name attribute to your submit button. If you assign a name then it is passed as part of the $_POST array.

    <input type="submit" value="My Button" />
    

    Since you no longer have the submit button in post, instead of checking if the submit button is set check to see if the post array contains data using count().

    if(count($_POST) > 0)
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度