duanmei1350 2017-10-22 12:49
浏览 124
已采纳

使用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 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"]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法