简体   繁体   中英

Only one button Submit don't working Why?

I have a problem with sending the button value "submit" . In practice I have this HTML:

  <div class="" role="tabpanel" data-example-id="togglable-tabs">
      <ul id="myTab" class="nav nav-tabs bar_tabs" role="tablist">
        <li role="presentation" class="active"><a href="#tab_content1" id="home-tab" role="tab" data-toggle="tab" aria-expanded="true">Modifica Testo</a>
        </li>
        <li role="presentation" class=""><a href="#tab_content2" role="tab" id="profile-tab" data-toggle="tab" aria-expanded="false">Modifica Foto</a>
        </li>
      </ul>
      <div id="myTabContent" class="tab-content">
          <div role="tabpanel" class="tab-pane fade active in" id="tab_content1" aria-labelledby="home-tab">
            <form action="update_chisiamo.php" class="form-horizontal form-label-left" method="post" enctype="multipart/form-data">
              <input type="hidden" name="idIto" value="<?php echo $res['idIto'];?>"/>
              <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Messaggio di Benvenuto</label>
                <div class="col-md-9 col-sm-9 col-xs-12">
                  <input type="text" class="form-control" name="benvenuto" value="<?php echo $res['benvenuto'];?>" placeholder="">
                </div>
              </div>
              <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Nome Pagina</label>
                <div class="col-md-9 col-sm-9 col-xs-12">
                  <input type="text" class="form-control" name="nome_pagina" value="<?php echo $res['titolo_page'];?>" placeholder="">
                </div>
              </div>
              <div class="form-group">
                <label class="control-label col-md-3 col-sm-3 col-xs-12">Descrizione</label>
                <div class="col-md-9 col-sm-9 col-xs-12">
                <textarea name="descrizione_page" class="form-control" placeholder=""><?php echo $res['descrizione_page'];?></textarea>
                </div>
              </div>
              <div class="ln_solid"></div>
              <div class="form-group">
                <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                    <button type="submit" name="btn-upload" class="btn btn-success">Modifica</button>
                </div>
              </div>
            </form>            
          </div>
          <div role="tabpanel" class="tab-pane fade" id="tab_content2" aria-labelledby="profile-tab">
              <form action="update_imgchisiamo.php" class="form-horizontal form-label-left" method="post" enctype="multipart/form-data">
                <input type="hidden" name="id" value="<?php echo $res['id'];?>"/>
                <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">File Foto</label>
                  <div class="col-md-9 col-sm-9 col-xs-12">
                    <?php echo $res['file'];?>
                  </div>
                </div>
                <div class="form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">Aggiungi Foto</label>
                  <div class="col-md-9 col-sm-9 col-xs-12">
                    <input type="file" name="file" />
                  </div>
                </div>

                <div class="ln_solid"></div>
                <div class="form-group">
                  <div class="col-md-9 col-sm-9 col-xs-12 col-md-offset-3">
                    <button type="submit" name="btn-upload" class="btn btn-success">Modifica</button>
                  </div>
                </div>
            </form>
          </div>
      </div>
   </div>

Are two tabs that allow you to change the one hand some data and on the other picture. In their submission pages of the form (which are different) I have the same control input of the global variable $ _POST , here is the simple code:

             if(isset($_POST['btn-upload'])) {
               // Code
             }

The problem lies in the second form that fails to send in the $ _POST parameter the name of the submit button.

Trying to print the contents of the array on the landing page I get the result that all the values ​​are present except $ _POST [ 'btn-upload'] which is not set.

I repeat that for the first form there is no problem. I looked at the code several times and seems to have no problems. I can not understand what is wrong.

as according to question line :

Trying to print the contents of the array on the landing page I get the result that all the values ​​are present except $ _POST [ 'btn-upload'] which is not set.

You not able to get submit contents because here you not add value for submit button:

<button type="submit" value="ADDVALUE" name="btn-upload" class="btn btn-success">Modifica</button>

I add value in your submit button. Try your code again.

For the second form, you have a hidden field (id) and a file field. The $_POST shows the id value but not the file values. For the file field you must use $_FILES. See this page in php.net and here's a page in w3schools that can help.

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