If you are in a <input>
only the message just use rawurlencode
, as in PHP:
<?php
if (!empty($_POST['message'])) {
$message = rawurlencode($_POST['message']);
$url = 'https://api.whatsapp.com/send?phone=seunumerodetelefone&text=' . $message;
var_dump($url); //Somente para testar a URL
}
Assuming the form is like this
<form action="pagina.php" method="POST">
<input type="text" name="message">
<button>Enviar</button>
</form>
If it's JavaScript you can use encodeURIComponent
:
var message = document.querySelector("#message"),
testBtn = document.querySelector("#testar");
testBtn.onclick = function () {
var url = 'https://api.whatsapp.com/send?phone=seunumerodetelefone&text=';
var urlmessage = url + encodeURIComponent(message.value);
console.log(urlmessage);
};
Digite algo: <input type="text" id="message" value=""><br>
<button id="testar">Enviar</button>