I'm working on a project where user can fill out his/her profile. So while storing user's social media links, I've a json file which has all the refrences like name, favicon, url. So I can foreach it using json_decode and display with a text field. But how do I store all the links entered in the database as json format and retrieve them with the full URL.
This is json file
{
"facebook": {
"icon": "fab fa-facebook",
"title": "Facebook",
"url": "https://facebook.com/%s"
},
"instagram": {
"icon": "fab fa-instagram",
"title": "Instagram",
"url": "https://instagram.com/%s"
}
}
This is how I'm displaying it
<?php foreach($available_buttons as $key => $button): ?>
<div class="col-md-4 mb-3">
<div class="form-group">
<label ><i class="<?= $button->icon ?> mr-2"></i> <?= $button->title ?></label>
<input type="text" name="buttons[<?= $key ?>]" class="form-control" />
</div>
</div
<?php endforeach; ?>
I'm processing it by using json_encode annd submitting it to db
$buttons = json_encode(clean_array($_POST['buttons']));
Passing the data in clean array function
function clean_array(Array $data) {
foreach($data as $key => $value) {
$data[$key] = filter_var($data, FILTER_SANITIZE_STRING);
}
return $data;
}
But when I try to submit i get false in database like "{'instagram': 'false', 'instagram': 'false'}"
How do I do it?