I am creating dynamic multi fields with PHP and JSON data. I am facing issues like 1st the foreach is not showing the data with the same keys like “text” field it is showing the one only in foreach loop. it should show.
1: input field with data (type text)
2: Textarea field with data
3: inputfield with data (type text)
but it is only showing 2 fields when I am running the code. Where I am mistaking?
And how to show the fields with types if the type is text then show the <input type="text" with data>
and if it is textarea then show <textarea with data></textarea>
please some one can help me out with this?
$json_test_data = '
{
"section_1":
[
{
"text":{"class":"mb-20","name":"text","value":"value 1","placeholder":"Section placeholder"}
},
{
"textarea":{"class":"mb-20","name":"section_content","value":"Section content 1","placeholder":"Section Content"}
},
{
"text":{"class":"mb-20","name":"value_2","value":"value 2 value","placeholder":"value 2 placeholder"}
}
]
}';
$json_test = json_decode($json_test_data, true);
$input = '';
if(is_array($json_test))
{
foreach ($json_test as $section => $section_data)
{
echo '<div class="model">';
echo '<div class="model-header d-flex"><h4>'.$section.' Data</h4></div>';
foreach($section_data as $section_fields => $fields_data)
{
foreach($fields_data as $field_key => $field_value)
{
if($field_key == 'text')
{
foreach($field_value as $field_keyy => $field_valuee)
{
$input .= $field_keyy.'="'.$field_valuee.'" ';
}
echo '<input '.$input.'>';
}
}
}
echo '</div>';
}
}