简体   繁体   中英

How to update dynamic options in php form

I want to divide and update dynamic options in input boxes in php form

Here is the output

test1-$11,test2-$23,test3-$12

I can add this fields in db just fine.

if(!empty($_POST["custom_name"][0])) {       
        foreach($_POST["custom_name"] as $k=>$v) {        

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

I want to display fields in input boxes and add or update them like this...............

在此处输入图像描述

Here is the reference code - https://phppot.com/php/php-contact-form-with-custom-fields/

I try to get your output via php. maybe it will help you

<?php 

$color="test1-$11,test2-$23,test3-$12";
$re = '/[a-zA-Z0-9]+-\$[0-9]+/m';
preg_match_all($re, $color, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $key => $value) {
    $value = $value[0]; 
    $label = explode('-',$value)[0]; // get label from string
    $value = explode('-',$value)[1]; // get value from string
    $value = str_replace('$','',$value); // repalce '$'
    ?>
    <div>
        <input type="text" value="<?php echo $label?>">
        <input type="text" value="<?php echo $value?>">
    </div>
    <?php
}
?>

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