In this code nothing will occur, since this action
is totally wrong. action
should call a POST API, but without passing parameters with PHP name on it.
What you want to do would be more or less:
<?php
if(isset($_POST['telefone'])){
$telefone = $_POST['telefone'];
$texto = $_POST['texto'];
$resposta = file_get_contents("https://api.whatsapp.com/send?phone=" . $telefone . "&text=" . $texto);
echo $resposta;
}
?>
<html>
<body>
<form action="" method="post">
<?php echo $resposta; ?>
<input type="text" name="telefone"/>
<input type="text" name="texto"/>
<input type="submit" name="SubmitButton"/>
</form>
</body>
</html>
Even so, it is not recommended. It is recommended to make use of jQuery, with each code in separate files, in the form of:
HTML ---> FORM ---> jQuery ---> PHP ---> WhatsApp API
You can even directly call the Whatsapp API from the form, assuming:
<form action="https://api.whatsapp.com/send/" method="POST" target="_blank">
<input type="text" name="text" placeholder="Digite sua mensagem..." autocomplete="off">
<input type="text" name="phone" placeholder="Insira o telefone (com o +55)..." autocomplete="off">
<button class="trwpwhatsappsendbutton" name="enviar" type="submit">
<i class="fa fa-paper-plane-o"></i>
</button>
</form>
In this way, text
and phone
would be sent to the API.
I tested it the way you did, but you don’t pull the information. The Whatsapp number should be hidden because it will not be changed by the user and I am using api.Whatsapp and web.Whatsapp for the link to work on both mobile and desktop.
– Eduardo