Placing a function within an input

0

Hello, I wanted to know how I put a random "passwords" function inside the input, the random password generation code is this:

function geraSenha($tamanho = 8, $maiusculas = true, $numeros = true, $simbolos = false)
{
    $lmin = 'abcdefghijklmnopqrstuvwxyz';
    $lmai = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $num = '1234567890';
    $simb = '!@#$%*-';
    $retorno = '';
    $caracteres = '';
    $caracteres .= $lmin;
    if ($maiusculas) $caracteres .= $lmai;
        if ($numeros) $caracteres .= $num;
            if ($simbolos) $caracteres .= $simb;
                $len = strlen($caracteres);
                for ($n = 1; $n <= $tamanho; $n++) {
                    $rand = mt_rand(1, $len);
                    $retorno .= $caracteres[$rand-1];
                }
    return $retorno;
}
?>

The Input code is this

<input name='AwardID' id='AwardID' type='text' value="Senha aleatoria" maxlength='40' value='' />

And how do you block input so you can not write? Thanks to anyone who can help me right away.

    
asked by anonymous 12.12.2016 / 14:30

1 answer

2
<input name='AwardID' id='AwardID' type='text' value="Senha aleatoria" maxlength='40' value='<?php echo geraSenha(8, true, true, false); ?>' readonly />

Just write the function return inside the Value property and to not allow changing the text add the readonly tag     

12.12.2016 / 14:40