Twilio evangelist here.
The Outgoing Calls sample code already includes the client side JavaScript to grab a phone number from an input field in the webpage and include it as a parameter in the connect()
function:
function call() {
// get the phone number to connect the call to
params = {"PhoneNumber": $("#number").val()};
Twilio.Device.connect(params);
}
Specifically this code: $("#number").val()
gets the value from an input field named number
.
One the server side, Twilio will take the collection of parameters that you provide to the connect
function and forward those to the URL you have specified as your TwiML Application URL as simple form-encoded values. You can use PHP's $_REQUEST
global function to grab those and dynamically generate a TwiML response:
<?php
if (isset($_REQUEST['PhoneNumber'])) {
$number = htmlspecialchars($_REQUEST['PhoneNumber']);
}
?>
<Response>
<Dial callerId="+15555555555">
<?php echo $numberOrClient ?>
</Dial>
</Response>
Hope that helps.