简体   繁体   中英

Form Data not sent via POST but works via GET in PHP

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:

PS 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM