duanmei1350
2017-10-22 12:49 阅读 90
已采纳

使用php WordPress提交表单

Hello I work with WordPress , and I create a custom Modal with form to add a Group called 'abonnement' I added the table in Database and this is my issue:

Form

<form name="abonnementCreate" action="create.php" method="POST">
  <div class="form-group">
    <label>Nom de l'abonnemnt</label>
    <input type="text" class="form-control" id="nomA" name="nomA">
  </div>
  <div class="form-group">
    <label>Durée</label>
    <input type="number" class="form-control" id="dureeA">
    <small id="dureeHelp" class="form-text text-muted">En jours</small>
  </div>
  <div class="form-group">
    <label>Nombre de produit autorisé</label>
    <input type="number" class="form-control" id="nbProdA">
  </div>
  <div class="form-group">
    <label>Frais d'abonnement (€)</label>
    <input type="number" class="form-control" id="fraisA">
  </div>
  <button type="submit" name="create" class="btn btn-primary">Valider</button>
</form>

and this is the action of the creation :

create.php

<?php
  include'admin.php';
  global $wpdb;

  if(isset( $_POST["create"]))
   {
     $wpdb->insert('abonnement', array(
     'nom' => '.$_POST["nomA"].',
     'duree' => '.$_POST["dureeA"].',
     'nbProd' => '.$_POST["nbProdA"].',
     'frais' => '.$_POST["fraisA"].' 
      ));
    }
 ?>

I have $_POST["create"] and the condition is true but $_POST[" any field"] is always null,
Someone please can help me ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    doushi3322 doushi3322 2017-10-22 13:37

    you can never catch the post value from id of the form input field.only way that you can get value using $_POST[] is using the "name" attribute of the input field.

        <input type="text" class="form-control" id="nomA" name="name1">
    

    this input field value can be accessed from form action php file using $_POST["name1"]

    点赞 评论 复制链接分享

相关推荐