0

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.

2 Answers 2

1

Either

$form .= "<textarea class='text' data-prefix='Message from: " . $foo. "' ></textarea>";

or

$form .= "<textarea class='text' data-prefix='Message from: {$foo}' ></textarea>";
Sign up to request clarification or add additional context in comments.

Comments

0

Try to concat PHP variable with your string

$form .= '<textarea class="text" data-prefix="Message from: '.$foo.'" ></textarea>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.