Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

JoaoGracio89's avatar

How to build dinamic forms from JSON to HTML (with variables some php code in the middle)

So a im building dinamic forms from JSON.

The SuperAdmin constructs a form it is stored as JSON then i want to render it in blade as HTML.

It seems simple so far. But when i start using variables from database as {{ Auth()->user()->name }}. Or maybe a piece of code PHP inside Blade things got more complicated.

The following code goes as an example:

return '<form class="'. $class .'" action="'. route($route) .'" method="POST" enctype="'. $enctype .'">'
            .'<input type="hidden" name="version" value="'. $version .'" >'
            .'<input type="hidden" name="form_id" value="'. $id .'" >'
            .'<input type="text" name="name" id="name" value="{{Auth()->user()->name}}" readonly="readonly" required >';

Where do i start? Is there any thing that covers this? Where do i start looking?

This is how i would transform it into HTML inside the page:

<?php
/**
 *
 * @var $form \App\Models\Form
 */
view()->share('pageTitle', $form->id);
view()->share('hideSubHeader', true);
?>
@extends('layout.default')
@section('breadcrumbs')
    {{-- Breadcrumbs::render('forms.show', $form) --}}
@endsection
@section('content')
    {!! $htmlLongText !!}
@endsection
@push('scripts')

@endpush

Thanks in advance!!!

0 likes
1 reply
JoaoGracio89's avatar
JoaoGracio89
OP
Best Answer
Level 6

It all comes down to:

eval("$result = $php;");

Where $php is Auth()->user()->name;

Any one doing this feel free to leave comment...

1 like

Please or to participate in this conversation.