I am constructing an html form in php with javascript and css, the following line of code works fine and displays a textarea with the required prefix:
$form .= '<textarea class="text" data-prefix="Message from: " ></textarea>';
However I want to include a php variable i.e
$form .= '<textarea class="text" data-prefix="Message from: $foo" ></textarea>';
This show the textarea with the prefix ‘Message from $foo’. How do I show it with the value of $foo combined into the data-prefix i.e ‘Message from Foo’?
Any advice would be appreciated, thanks.
Advertisement
Answer
Try to concat PHP variable with your string
$form .= '<textarea class="text" data-prefix="Message from: '.$foo.'" ></textarea>';