Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php表单中动态发送输入和选择字段_Php_Forms_Post - Fatal编程技术网

在php表单中动态发送输入和选择字段

在php表单中动态发送输入和选择字段,php,forms,post,Php,Forms,Post,我有一个股票视频申请表,人们可以申请一定长度的股票视频。我有一个可见的表单发送很好,因为我可以发布它的“名称”,但人们可以“添加更多”,如果他们想要一些剪辑 我不知道如何将这些动态创建的选择和输入字段添加到我的PHP$\u帖子中。。。将它们添加到一个数组中,并将其导出?或者只是将它们全部添加到一个对象,然后$\u发布该对象 非常感谢您的帮助 HTML(注意inputGroupSelect02是每次单击“添加更多”时动态添加的部分 <?php include("phpInclude

我有一个股票视频申请表,人们可以申请一定长度的股票视频。我有一个可见的表单发送很好,因为我可以发布它的“名称”,但人们可以“添加更多”,如果他们想要一些剪辑

我不知道如何将这些动态创建的选择和输入字段添加到我的PHP$\u帖子中。。。将它们添加到一个数组中,并将其导出?或者只是将它们全部添加到一个对象,然后$\u发布该对象

非常感谢您的帮助

HTML(注意inputGroupSelect02是每次单击“添加更多”时动态添加的部分

<?php include("phpIncludes/header_nav.php") ?>


<section id="cinecoptersShowreel">



<!--CONTACT-->

<div id="contact" class="container contact-form">

<div id="contactAnchor"></div><!--CONTACT ANCHOR TAG-->


<form id="stockRequestWrapper" method="post" action="stockForm.php">
    <h3>Stock Footage Request</h3>
  <div class="row">
    
    <div class="col">
      <div class="form-group">
        <input id="nameInput" type="text" onchange="filledIn(this)" name="name" class="form-control" placeholder="Name *" value="" />
      </div>
      <div class="form-group">
        <input id="emailInput" type="text" onchange="filledIn(this)" name="email" class="form-control" placeholder="Email *" value="" />
      </div>
      <div class="form-group">
        <input id="companyInput" type="text" name="company" class="form-control" placeholder="Company" value="" />
      </div>
    </div>

    <div id="formAdd" class="col">
      <div class="form-group">
        <select id="inputGroupSelect" name="stock" onchange="filledIn(this)" class="custom-select"  >
          <option id="chooseOption" selected>Stock Section...*</option>
          <option>Belfast</option>
          <option>Derry</option>
          <option>Dublin</option>
          <option>Water</option>
          <option>Countryside</option>
          <option>Misc</option>
        </select>

        <!-- <span class="text-primary">Please input   <strong>hours : mins : secs</strong>   only.  Frames are not required</span> -->
        <div class="input-group after-add-more"> 
          <div class="input-group-prepend">
            <span class="input-group-text">mm:ss</span>
          </div>
          <input id="tcIn" name="tcIn" type="time" onchange="filledIn(this)" step="any" class="form-control" >
          <span> to </span>
          <input id="tcOut" name="tcOut" type="time" onchange="filledIn(this)" step="any" class="form-control">
        </div>
        <input id="addMore"  type="button" value="Add more" class="btn add" />

      <div class="form-group">
        <input id="btnStockSubmit" disabled type="submit" name="btnStockSubmit" class="btn btn-success" value="Submit Stock Request" />
      </div>

</form>



<!-- HIDDEN  bits that are being copied when addmore is clicked if we copy the above form it will copy all items - so if theres 4 items there will be 8 rather than just adding one each time -->
<div class="copy hide">
  <div class="control-group input-group test">
    <hr>
        <select class="custom-select" id="inputGroupSelect02" name="stock2">
          <option value="" selected disabled>Stock Section</option>
          <option value="1">Belfast</option>
          <option value="2">Derry</option>
          <option value="3">Dublin</option>
          <option value="4">Water</option>
          <option value="5">Countryside</option>
          <option value="6">Misc</option>
        </select>

      <div class="input-group-prepend">
        <span class="input-group-text" name="addmore[]">mm:ss</span>
      </div>
    <input  type="time" step="any" class="form-control">
    <span> to </span>
    <input type="time" step="any" class="form-control">
    <div class="input-group-btn"> 
      <button class="btn btn-danger remove" type="button"><i class="glyphicon glyphicon-remove"></i> -</button>
  </div>
  </div>

</div>



      </div>
    </div>
</div>




    </div>

  </div>
</form>
</div>

<!--/CONTACT-->






</section>


<?php include("phpIncludes/footer.php") ?>
PHP POST表单

<?php
if(isset($_POST['btnStockSubmit'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "EMAIL@EMAIL.COM";
    $subject = "Stock Submission Form";



    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }

    $full_name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $company = $_POST['company'];
    $stock = $_POST['stock'];
    $tcIn = $_POST['tcIn'];
    $tcOut = $_POST['tcOut'];



    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The e-mail you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$full_name)) {
    $error_message .= 'The name you entered does not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($full_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Company: ".clean_string($company)."\n";
    $email_message .= "Stock Reel: ".clean_string($stock)."\n";
    $email_message .= "TC In: ".($tcIn)."\n";
    $email_message .= "TC Out: ".($tcOut)."\n";
    $email_from = $full_name.'<'.$email_from.'>';


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $subject, $email_message, $headers);



?>

<!-- include your own success html here -->
<?php include ("phpIncludes/header_nav.php") ?>

<h1>Thanks for your message. We'll get back to you ASAP!</h1>

<?php include ("phpIncludes/footer.php") ?>



<?php
}
?>

谢谢你的留言。我们会尽快回复你的!

我不明白您的实际问题是什么。看起来您并不是在使用AJAX,而是在正常提交表单……因此所有字段的值都将在$\u POST中提供(如果您正确命名的话),这并不是你需要特别促进使用任何额外的步骤。问题是如何将动态创建的项目添加到帖子中。不使用AJAX no。如果你有多个同名表单字段,那么你需要使用
foo[]
使用大括号表示字段名的语法,否则PHP将覆盖这些参数,您将只获得最后一个参数。
<?php
if(isset($_POST['btnStockSubmit'])) {

    // EDIT THE 2 LINES BELOW AS REQUIRED
    $email_to = "EMAIL@EMAIL.COM";
    $subject = "Stock Submission Form";



    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['name']) ||
        !isset($_POST['email'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }

    $full_name = $_POST['name']; // required
    $email_from = $_POST['email']; // required
    $company = $_POST['company'];
    $stock = $_POST['stock'];
    $tcIn = $_POST['tcIn'];
    $tcOut = $_POST['tcOut'];



    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The e-mail you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$full_name)) {
    $error_message .= 'The name you entered does not appear to be valid.<br />';
  }

  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($full_name)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Company: ".clean_string($company)."\n";
    $email_message .= "Stock Reel: ".clean_string($stock)."\n";
    $email_message .= "TC In: ".($tcIn)."\n";
    $email_message .= "TC Out: ".($tcOut)."\n";
    $email_from = $full_name.'<'.$email_from.'>';


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $subject, $email_message, $headers);



?>

<!-- include your own success html here -->
<?php include ("phpIncludes/header_nav.php") ?>

<h1>Thanks for your message. We'll get back to you ASAP!</h1>

<?php include ("phpIncludes/footer.php") ?>



<?php
}
?>