dongwh1992 2014-08-30 06:31
浏览 21

表单数据不是通过POST发送的,而是通过PHP中的GET工作

This is pretty weird. I have tried everything. I see no notable issue here. Thought, may be either of you could lend me a helping hand in this issue. I am badly stuck here.

When I press the submit button in the form below, no data is sent. I am made sure that I did not miss the name attribute, but I totally do not understand the issue.

var_dump($_POST)

array empty

The most interesting part of this error is, if I set the method to GET, the values are passed.

var_dump($_GET);

GET Method Result:

array
  'song_file' => string '19 Jillian.m4a' (length=14)
  'song_name' => string 'Jillian' (length=7)
  'singer_name' => 
    array
      0 => string 'Heitor Pereira' (length=14)
      1 => string '' (length=0)
      2 => string '' (length=0)
      3 => string '' (length=0)
      4 => string '' (length=0)
      5 => string '' (length=0)
  'lang' => 
    array
      0 => string '2' (length=1)
  'allow_downloading' => string 'yes' (length=3)
  'add_song' => string 'Add' (length=3)

The form code is as below. Here, I tried out with post method.

<form class="form" action="" enctype="multipart/form-data" method="post">
  <fieldset>
    <div class="row">
      <label class="label" for="song-file">Please select a track to upload*</label>
      <input id="song-file" name="song_file" class="field" type="file" />
    </div>
    <div class="row">
      <label class="label" for="song-name">Song Name :</label>
      <input id="song-name" name="song_name" class="field" type="text" size="42" />
    </div>
    <div class="row">
      <label class="label">Artists :</label>
      <div class="field-row">
        <input name="singer_name[]" class="field" type="text" size="25" />
        <input name="singer_name[]" class="field" type="text" size="25" />
      </div>
      <div class="field-row">
        <input name="singer_name[]" class="field" type="text" size="25" />
        <input name="singer_name[]" class="field" type="text" size="25" />
      </div>
      <div class="field-row">
        <input name="singer_name[]" class="field" type="text" size="25" />
        <input name="singer_name[]" class="field" type="text" size="25" />
      </div>
    </div>
    <div class="row">
      <label class="label" for="allow-downloading"> Allow Downloading</label>
      <select name="allow_downloading" class="dropdown">
        <option value="yes">Yes</option>
        <option value="no">No</option>
      </select>
    </div>
    <input type="submit" name="add_song" value="Add" class="btn" style="float:none;" />
  </fieldset>
</form>

As per the suggestion, here is a snippet of my PHP Code that this form uses:

P.S. I am using Code Igniter at the backend. All other forms are working well, expect for this one.

class Song extends CI_Controller {

    public function add($album_id){

        if($_POST){
            var_dump($_POST);
        }

        $this->load->view('album/form.php');
    }
}

Any help will be highly appreciated.

  • 写回答

1条回答 默认 最新

  • dshu1235 2014-08-30 07:39
    关注
    1. May be you have some JS submit handler, which, for example, prevent default submit action, collect all form data and send it through ajax with GET method?

    2. May be CodeIgniter do some magic with POST data. To know it for sure dump $_POST array before CodeIgniter core initialization.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集