1

I would like to create custom confirmation messages that could be easily updated by the admins.

Like

 <textarea>You can contact {contact_name} located at {contact_place}…</textarea>

contact_name and contact_place are fields that will be completed in the same form, and are both required.

Is it something easy to manage?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • don's think you would be able to achieve this with PHP. If understood correctly, you would like to fill contact_name and contact_place on the fly once the corresponding fields are filled in the form. Is that right? – Yevgeniy Oct 07 '21 at 07:29
  • Not exactly. For example, in my view(), I would like to identify {contact_name} and {contact_place} and replace them dynamically with the appropriate fields, for example event->name and event->place. –  Oct 07 '21 at 10:44
  • 1
    if you have data in a variable at the time of generating the form you could stick it in HTML like so: ``. Or do you generate your form using `= $this->Form->control('textarea_field_name') ?>`? – Yevgeniy Oct 07 '21 at 11:24

1 Answers1

0

Save the text string with placeholders in db, then use str_replace in custom Helper or in entity virtual fields

   return str_replace(
      [
         '{{contact_name}}', // placeholders
         '{{contact_place}}', 
         '{{email}}',
      ],
      [
         $contact->name, // inputs
         $contact->place,
         $contact->email,
      ],
       // load template string from db
      // You can contact {{contact_name}} located at {{contact_place}}…
      $admin->template
   );

   
Salines
  • 5,674
  • 3
  • 25
  • 50