Question:
I am making a web application and I would like to include a different .php page for each option in the select
. I tried include
and require
but it still doesn't work for me.
I have tried to do this, but it doesn't work for me:
<select id="idioma" name="idioma">
<option action="<?php require ('../Vista/lang/lang_es.php'); ?>" value="es" selected="selected">Español</option>
<option action="<?php require ( '../Vista/lang/lang_en.php'); ?>" value="en">Inglés</option>
</select>
How could I fix it?
Answer:
What you are trying to do is not feasible since you are on the client side.
I can think of that way to do it:
Through a post
<?php
$includes=array(
'en'=>'../Vista/lang/lang_en.php',
'es'=>'../Vista/lang/lang_es.php'
);
if(isset($_POST['idioma']) && array_key_exists($_POST['idioma'], $includes)) :
include($includes[$_POST['idioma']]);
endif;
?>
<form id="selection_form" action="" method="post">
<select name="idioma" id="idioma">
<option value ="es">Español</option>
<option value ="en">Inglés</option>
</select>
<input type="submit" name="idioma_submit" value="GET FILE">
</form>