Lucy Weatherford
Lucy Weatherford

Reputation: 5534

Inserting PHP variable into Html5 "Placeholder" attribute

I tried the following, and it shows an empty text area, the value isn't displayed:

    <input type="textarea" class="class1" name="name1" placeholder="<?= $val1?>" /> 

Any thoughts on what should be done so it will work?

Update: It is now working, the value was empty, therefore text area didn't show anything. The code can be used safely.

Upvotes: 1

Views: 23630

Answers (4)

Zul
Zul

Reputation: 3608

if $val1 is not null, i think the problem is short tag (<?= ?>).

You can override this config, at the top of file, put this line to enable short tag:

ini_set('short_open_tag',1);

Upvotes: 3

Asaph
Asaph

Reputation: 162801

Make sure that $val1 actually contains a non-empty value. If it does, your code should create a non-empty placeholder attribute.

Upvotes: 2

Lucy Weatherford
Lucy Weatherford

Reputation: 5534

Check whether the variable is empty (as @Asaph suggested in his comment). Entered a value and now it is working just fine.

Upvotes: 0

Jonathan
Jonathan

Reputation: 5547

<input type="textarea" class="class1" name="name1" placeholder="<?php echo $val1; ?>" />

There is no such input type attribute as textarea.

Do you mean:

<textarea class="class1" name="name1" placeholder="<?php echo $val1; ?>"></textarea>

Upvotes: 3

Related Questions