Set placeholder with PHP variable [closed]

-3

I have a Registration / Search Form and now I'm adding the option to edit the fields. For the clerk not to get confused, I wanted to set the placeholder with a PHP variable, via echo . Is it possible to do this?

<div class="inputs">
    <?php if ($id != '') { ?>
        <input type="hidden" name="id" value="<?php echo $id; ?>" />ID: <?php echo $id; ?>
    <?php } ?> 
    <?php echo $cliente; ?>
    <input type="text" name="cliente" maxlength="50" placeholder="<?php echo $cliente; ?>" value="<?php echo $cliente; ?>"/><br/>
    <input type="text" name="produto" maxlength="25" placeholder="PRODUTO" value="<?php echo $produto; ?>"/><br>
    <input type="text" name="solicitante" maxlength="50" placeholder="SOLICITANTE" value="<?php echo $solicitante; ?>"/><br/>
    <input type="text" name="status" maxlength="25" placeholder="STATUS" value="<?php echo $status; ?>"/><br/>
    <input type="text" name="incluiu" maxlength="25" placeholder="INCLUIU" value="<?php echo $incluiu; ?>"/><br/>
    <input id="submit" class="button_text" type="submit" name="submit" value="Cadastrar" />
</div>
    
asked by anonymous 22.10.2014 / 19:40

4 answers

6

Yes, it is possible:

<input type="text" placehold="<?php  echo 'palavra'; ?>" />
    
22.10.2014 / 19:54
3

It only makes sense to use this if the variable is different from the field because the placeholder only appears with empty field. And the way you're doing, the placeholder will only be used empty anyway. Probably something would have to be done in this sense:

<input type="text" name="cliente" maxlength="50" placeholder="<?php echo 'CLIENTE'; ?>"
   value="<?php echo $cliente; ?>"/><br/>

Or even so:

$pla_cliente = 'Cliente';
... seu código PHP ...

<input type="text" name="cliente" maxlength="50" placeholder="<?php echo $pla_cliente; ?>"
   value="<?php echo $cliente; ?>"/><br/>

but always using different variables for the placeholder and for the field.


If you are trying to use the reset value of the fields, just use reset to return the previous value

    
22.10.2014 / 20:32
1

With JavaScript you can do this:

var placeholder = document.getElementById("entrada").getAttribute("placeholder");
alert(placeholder);
<input type="text" placeholder="teste" id="entrada">
    
22.10.2014 / 19:58
1

The change I suggest is as follows:

<input type="text" name="cliente" maxlength="50" placeholder="<?php echo $cliente; ?>" value="<?php echo $cliente; ?>"/><br/>

Note that you are setting the placeholder and then replacing value

In case you remove the value and see that the placeholder is working correctly.

<input type="text" name="cliente" maxlength="50" placeholder="<?=
$cliente; ?>"/><br/>
    
22.10.2014 / 20:55