Without needing to give too much info on the API in use, I'm trying to get the option value to match what's being wrapped inside the option tag.
Something like this:
<option value="Foo">Bar</option>
Here's the PHP:
<?php
$counter = 0;
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
"AreaCode" => $_POST["areacode"]));
echo "<select>";
foreach($numbers->available_phone_numbers as $number) {
echo "<option value=''>";
echo $number->phone_number;
$counter++;
echo "</option>";
echo "<br>";
}
echo "</select>";
echo "<br>";
echo $counter;
?>
With this form:
<form action="index.php" method="post">
Area Code:<br>
<input type="text" name="areacode" value=""><br>
<input type="submit" value="Submit">
</form>
Your syntax is incorrect.
echo '<select>';
foreach($numbers->available_phone_numbers as $number) {
echo '<option value="' .$number->phone_number .'">';
echo $number->phone_number;
echo '</option>';
}
echo '</select>';
Also, you shouldn't have a br
tag in your select
element.
Change echo "<option value=''>";
to echo "<option value='{$number->phone_number}'>";
I think you need to move the select inside the form tag in order to submit the selected data also.
<form action="index.php" method="post">
echo "<select>";
foreach($numbers->available_phone_numbers as $number) {
echo "<option value='".$number->phone_number."'>";
echo $number->phone_number;
$counter++;
echo "</option>";
echo "<br>";
}
echo "</select>";
echo "<br>";
echo $counter;
?>Area Code:<br>
<input type="text" name="areacode" value=""><br>
<input type="submit" value="Submit">
</form>
Hope this help
<?php
$counter = 0;
$numbers = $client->account->available_phone_numbers->getList('US', 'Local',
array(
"AreaCode" => $_POST["areacode"]
));
?>
<form action="index.php" method="post">
<?php
echo "<select>";
foreach($numbers->available_phone_numbers as $number) {
echo "<option>" . $number->phone_number . "</option>";
$counter++;
}
echo "</select>";
?>
<input type="submit" value="Submit">
</form>