Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/06/2015, 03:05
AsturieshXc
 
Fecha de Ingreso: junio-2015
Ubicación: Mieres
Mensajes: 4
Antigüedad: 8 años, 11 meses
Puntos: 0
Pregunta Select option PHP + ¿Javascript?

Hola buenos días, soy nuevo por aquí y querría consultar una pequeña duda que tengo verán. Estoy programando una aplicación web en la cual requiere que a raiz de un código postal haga una llamada a un web service y me de las sucursales más cercanas de correos. Hasta ahí todo bien, consigo la respuesta y cargo un array con todas las oficinas. Pero lo que quiero hacer es cargar las oficinas en un select y mostrar la información del array más abajo, me imagino que sea utilizando javascript o ajax pero no soy capaz a realizarlo pido un poco de ayuda si sois tan amables. Os paso parte de mi código si os sirve para ayudarme.

Muchas gracias a todos

Código:
<html>

<?php

	function sendXmlCorreos($url, $xmlSend, $usuario_correos = false, $clave_correos = false, $SOAPAction = false)
    {

		$URL ="http://localizadoroficinas.correos.es/localizadoroficinas";
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $URL);
		
        if($usuario_correos) curl_setopt($ch, CURLOPT_USERPWD, $usuario_correos.":".$clave_correos);
		
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
        
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlSend);
        curl_setopt($ch, CURLOPT_FORBID_REUSE, TRUE);
		if($SOAPAction)
			curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml; charset=utf-8", "SOAPAction: \"{$SOAPAction}\""));
        else
			curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml; charset=utf-8"));
			
		curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
        $result = curl_exec($ch);
      
	  if($result === false) {
			$err = 'Curl error: ' . curl_error($ch);
			curl_close($ch);
			return $err;
		}
		
      
       
        curl_close($ch);
        return $result;

	}
	
	
	function GetOficinas_ws($postcode)
	{
		//  Prepare the code 
		$xmlSend = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ejb="http://ejb.mauo.correos.es"><soapenv:Header/><soapenv:Body><ejb:localizadorConsulta><ejb:codigoPostal>' . $postcode . '</ejb:codigoPostal></ejb:localizadorConsulta></soapenv:Body></soapenv:Envelope>';
			
		//  send curl
		$data =sendXmlCorreos('url_localizacion_oficinas', $xmlSend);
		
		
			$dataXml = simplexml_load_string($data, NULL, NULL, "http://schemas.xmlsoap.org/soap/envelope/");
			$dataXml->registerXPathNamespace('ns', 'http://ejb.mauo.correos.es');  
			
			$_tmpData = array();
            $_tmpData['unidad'] = $dataXml->xpath('//ns:unidad');
            $_tmpData['nombre'] = $dataXml->xpath('//ns:nombre');
		    $_tmpData['direccion'] = $dataXml->xpath('//ns:direccion');
            $_tmpData['localidad'] = $dataXml->xpath('//ns:descLocalidad');
            $_tmpData['cp'] = $dataXml->xpath('//ns:cp');
            $_tmpData['telefono'] = $dataXml->xpath('//ns:telefono');
            $_tmpData['horariolv'] = $dataXml->xpath('//ns:horarioLV');
            $_tmpData['horarios'] = $dataXml->xpath('//ns:horarioS');
            $_tmpData['horariof'] = $dataXml->xpath('//ns:horarioF');
            $_tmpData['coorx'] = $dataXml->xpath('//ns:coorXWGS84');
            $_tmpData['coory'] = $dataXml->xpath('//ns:coorYWGS84');
            
            for ($indice = 0; $indice< count($_tmpData['unidad']); $indice++)
            {
                foreach($_tmpData as $_data => $_value)
                {
                    $_oficinas[$indice][$_data] =  str_replace("'","", (string) $_value[$indice]);
                }
            }
            
  
            if (empty($_oficinas)) return false;
            else return $_oficinas;
			
			
		
		
	}
	
	$cpOfi=$_POST["cpOfi"];
	$oficinas=GetOficinas_ws($cpOfi);

	?>

	<form method="POST" action="loc_oficina.php">

	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
	<p>C.P.:<input type="text" name="cpOfi" id="cpOfi" value="<?php echo($cpOfi);?>"><input type="submit" value="Buscar oficina"></p>
	</p>Oficina:<select name="oficinas_correos" id="oficinas_correos" onChange="probar();">
	<option value="">Seleccione una oficina</option>
	<?php
	
	for($i=0;$i<count($oficinas);$i++)
	{
		if(!empty($oficinas))
		{	
		echo("<option value='".$i."'>".utf8_decode($oficinas[$i]['direccion'])."</option>");
		}
		
	}
	?>
	</select>

</form>
</body>