Unlink functions from PHP 'buttons'

Asked

Viewed 47 times

2

I would like to unlink the buttons, I have a button to generate password and one to call, but every time a password, it also calls, I would like to unlink these buttons, someone could help me please?

  <?php
  echo "<form>";
  echo "<button> Gerar senha</button>";
  echo "</form>";
  $letras = range('A', 'Z');
  $numeros = range(1, 9);
  shuffle($letras);
  shuffle($numeros);
  $senha = implode('', array_slice($letras, 3, 3)) . '-' . 
  end($numeros);
  $file = 'senhas.txt';
  if (!$handleFile = fopen($file, "a+")) {
  die("<p>Erro ao abrir/criar o arquivo: (<b>$file</b>) 
  </p>");
  }
  fwrite($handleFile, $senha . "\r\n");
  fclose($handleFile);
  $arr = (file_get_contents($file));
  echo '<pre>';
  print_r($arr);
  echo '</pre>';
  echo "<hr>";
  ?>
  <?php
  echo "<form>";
  echo "<button> Chamar senha</button>";
  echo "</form>";
  print_r("Senha $senha dirija-se ao caixa de atendimento");
  ?>
  • Bruno I don’t quite understand the question, but I’ll answer what I think I understand. Your code is all global, so it runs regardless of pressing the button, right? What you could do is put the buttons to respond to events with Javascript, and so call the PHP functions with the logic of each. For what I’m suggesting needs some more complex things to resolve this, like Ajax requests. You would have to create separate files for PHP logic and for the HTML page. [See this answer with an example to solve your problem. ](https://stackoverf

No answers

Browser other questions tagged

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