PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, March 11, 2022

[FIXED] How to add variables in a form textarea

 March 11, 2022     cakephp, cakephp-4.x, php     No comments   

Issue

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?


Solution

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
   );

   


Answered By - Salines
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing