Placing a function inside an input

Asked

Viewed 276 times

0

Hello wanted to know how to put a function of random "passwords" inside the input, the code generate random password 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’t write? I thank anyone who can help me right now.

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 return of the function inside the property Value and not to allow changing the text add the tag readonly

  • Don’t load that part when I do it like this: http://prntscr.com/diglvl

  • Sorry, take the word Function after echo

  • Thanks friend help me a lot, a question, has to create a button that when you press generates another password and so on?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.