简体   繁体   English

html php表格中如何回显和更新动态选项

[英]How echo and update dynamic options in html php form

I want to echo and update these options in php update / edit form.我想在 php 更新/编辑表单中回显和更新这些选项。

Here is the html input dynamic text box options -这里是html输入动态文本框选项——

Here is the complete code reference.这是完整的代码参考。 https://phppot.com/php/php-contact-form-with-custom-fields/ https://phppot.com/php/php-contact-form-with-custom-fields/

<div class="input-row">                          
          <input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" name="custom_name[]" />                           
          <input style="width:49%!important; float:right;" type="number"  placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" name="custom_value[]" />                                
 </div>

Code to enter in database输入数据库的代码

INSERT INTO custom_contact (name,email,subject,email_content,message,options) VALUES ('$name','$email','$subject','$emailContent','$message','$options')

if(!empty($_POST["custom_name"][0])) {
       // $emailContent .= "<p><u>Custom Information:</u></p>";
        foreach($_POST["custom_name"] as $k=>$v) {            

            $emailContent .=  "" . $_POST["custom_name"][$k] . "-" . $_POST["custom_value"][$k] . ",";

        }
    }

How to echo and edit these options and fields in php如何在 php 中回显和编辑这些选项和字段

Here is my sample edit/update code - I don't know what to put in value=""这是我的示例编辑/更新代码 - 我不知道在 value="" 中输入什么

Example -例子 -

<input style="width:49%!important; float:left;" type="text" placeholder="Option name" required class="custom-input-field" value="<?php echo$[0]["custom_name"];?>" name="custom_name[]" /> 

<input style="width:49%!important; float:right;" type="number" placeholder="Price" min="0" step="0.01" required class="custom-input-field float-right" value="<?php echo$["custom_value"][$k];?>" name="custom_value[]" />

The same way you are doing a foreach loop in the first part, you can echo HTML onto the page.与您在第一部分中执行 foreach 循环的方式相同,您可以将 HTML 回显到页面上。 Here is an simple example:这是一个简单的例子:

<?php
$arr = [0, 1, 2, 3];

foreach($arr as $number){

echo "<input type='text' value='".$number."' />";

}
?>

Or if you prefer, you can break in and out of PHP and HTML to make it easier to type if there's a lot of html:或者,如果您愿意,您可以插入和退出 PHP 和 HTML,以便在有很多 html 时更容易键入:

<?php
$arr = [0, 1, 2, 3];

foreach($arr as $number){
?>

<input type='text' value='<?php echo $number; ?>' />

<?php
}
?>

Edit: so I'm not really understanding what you're asking but let's say you have an array with two items编辑:所以我不太明白你在问什么,但假设你有一个包含两个项目的数组

$arr = [
     [ 
          “name”=>”first”,
          “value”=>1
     ],
     [
          “name”=>”second”,
          “value”=>2
      ]
];

You could loop on them and access the properties like so:您可以循环访问它们并像这样访问属性:

foreach($arr as $item)
{
     echo $item[“name”];
     echo $item[“value”];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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