Search code examples
phpgettags

How to insert php value into html tag by $_GET['NameField']


i want to fill value into html tag bij php Url post The orignalcode is

<div class="addevent" data-event='{
                            "title":"Appointment titel", 
                            "start":"2020/01/25 10:00", 
                            "end":"2020/01/25 12:00", 
                            "desc":"Description of appointment",
                            "location":"somewhere"
                            }'>

I tried this:

"title":<?php $_GET['titel']?>,

i received the values bij url post <?php $_GET['titel']?>
<?php $_GET['start']?> etc


Solution

  • Create a PHP array with all the values, and use json_encode() to convert it to JSON for the data-event attribute.

    $event = json_encode(['title' => $_GET['titel'], 'start' => $_GET['start'], ...]);
    ?>
    <div class="addevent" data-event='<?php echo htmlentities($event); ?>'