I have an array with a list of states and I am trying to get it to show up in my select list. I am getting no errors, but nothing is showing up in the select list as an option. I am just trying to get it to loop through the array and display the states in the HTML.
function statesList() {
$states = array('AL'=>"Alabama",
'AK'=>"Alaska",
'AZ'=>"Arizona",
'AR'=>"Arkansas",
'CA'=>"California",
'WY'=>"Wyoming");
return $states;
}
$email_form = '<?php $states = statesList(); ?>
<form class="aw-contact-form" method="post" action="' . get_permalink() . '">
<label for="cf_state">' . $label_state . '</label>
<select name="state" id="cf_state">
<option selected="selected"></option>
<?php foreach($states as $key=>$value) { ?>
<option value="<?php echo $key; ?>"><?php $value; ?></option>
<?php } ?>
</select>
</form>';
return $email_form;
Is my syntax wrong? Any help will be greatly appreciated.
<?php
inside a string, it can only be used when you're outside the PHP script, to get back into PHP execution mode. – Barmar Jul 3 at 6:05