Im making an "admin" page to upload photos to different categories, so there is an <input type="file">
and a <select>
that contains categories and subcategories organized in optgroups if a category have a subcategory, or just without the optgroup if it is just a category.
<?php echo form_open_multipart('principal/subir_foto');?>
<div class='input-group'>
<label for="img" class='control-label'>Seleccionar:</label>
<input id="img" required="true" type='file' name='imagen'/>
</div>
<div class='input-group'>
<label for="categoria" class='control-label'>Elegir Categoria:</label>
<select class='selectpicker form-control' name='cat_op' data-width='auto'>
<?php
foreach ($categorias as $row_cat) {
if($row_cat->tiene_subcat > 0){
echo "<optgroup value='".$row_cat->nom_cat ."' label='". $row_cat->nom_cat ."'>";
foreach ($subcat as $row_subcat) {
if($row_subcat->id_cat === $row_cat->id_cat){
echo "<option value=". $row_subcat->nom_subcat ."> ". $row_subcat->nom_subcat ."</option>";
}
}
echo "</optgroup>";
}
else{
echo "<option value='" . $row_cat->nom_cat . "'>". $row_cat->nom_cat . "</option>";
}
}
?>
</select>
</div>
<div class='input-group'>
<input type='submit' name='agregar' value="Agregar">
</div>
</form>
So when the code is interpreted by the server, the <select>
tag appears like this:
<label class='control-label'>Elegir Categoria:</label>
<select class='selectpicker form-control' name='cat_op' data-width='auto'>
<optgroup value='SALAS' label='SALAS'>
<option value=RAWSON> RAWSON</option>
<option value=CAPITAL> CAPITAL</option>
</optgroup>
<option value='SERVICIOS FUNERARIOS'>SERVICIOS FUNERARIOS</option>
<option value='ATAUDES'>ATAUDES</option>
<option value='FLORES'>FLORES</option>
</select>
So, when the submit button is pressed, in my Code Igniter controller named "Principal" and in the method "subir_foto" I can get access to $this->input->post('cat_op') thats gives me the option selected when submit, but how can I get the optgroup value also, because I need to have the subcategory and category name. I hope I have expressed my problem well
This is how the selectpicker is displayed
Thanks, is my first question.