Reputation: 19733
I am trying to get the option value from a selectbox but is isn't working:
HTML:
<form action="" method="post" name="module_gen">
<select id="module_gen_select_ver" name="module_gen_select_ver">
<option value="joomla15">Joomla 1.5</option>
<option value="joomla25_30">Joomla 2.5/3.0</option>
</select>
</form>
PHP:
if(isset($_POST['module_gen_select_ver'] ) == 'joomla15') {
$xmldata = '</install>';
}
elseif(isset($_POST['module_gen_select_ver'] ) == 'joomla25_30') {
$xmldata = '</extension>';
}
Wne I click the submit button, it doesn't seem to be taking the value of the option into account.
Can anyone show me as to where I have gone wrong?
Upvotes: 1
Views: 327
Reputation: 1208
Your if logic is flawed, due to a bracketing error. Right now, you are comparing isset($_POST['module_gen_select_ver'] )
to 'joomla15'
. I believe you intend to compare $_POST['module_gen_select_ver']
to 'joomla15'
.
Upvotes: 3
Reputation: 3780
Your if conditions are wrong.
if(isset($_POST['module_gen_select_ver'] ) == 'joomla15')
is getting the return value of isset($_POST['module_gen_select_ver'] )
, which is a boolean, then comparing it to 'joomla15'
, so the condition is not met. It should be:
if(isset($_POST['module_gen_select_ver']) and $_POST['module_gen_select_ver'] == 'joomla15')
The condition is still safe, as if it isn't set, the second condition won't even be read for all intents and purposes.
Or you could simply wrap both the if and elseif in if(isset($_POST['module_gen_select_ver'])
then removing it from the if and the elseif, Thusly:
if(isset($_POST['module_gen_select_ver'])
{
if($_POST['module_gen_select_ver'] == 'joomla15')
//etc
Upvotes: 4