Error in code with Joomla API 1.5: to use a variable that receives a post request with JRequest:: getVar
I am using the joomla framework to return values from a POST request, and the print screen shows me data, but when using the array in sending me to a method and print or send me data.
Here I put the code that I've got gray hair,thanks in advance.
This is the controller:
/**
* Construct (registers additional tasks to methods).
*/
function __construct(){
parent::__construct();
//Registro de tareas extra
$this->registerTask('add','ingresarPlanilla');
}//function
function ingresarPlanilla(){
// Comprueba del request la clave de falsificación
//JRequest::checkToken('post') or die( 'Objeto invalido' );
$task = JRequest::getVar('task');
$model = &$this->getModel('planilla');
if ($returnid = $model->ingresar()) {
switch ($task) {
case 'add' :
$link = '?option=com_mercurio&view=planilla&controller=planilla&task=add';
break;
default :
$link = 'index.php?option=com_mercurio&view=planilla';
break;
}
$msg = JText::_( 'PLANILLA INGRESADA' );
$cache = &JFactory::getCache('com_mercurio');
$cache->clean();
} else {
$msg = 'PLANILLA NO INGRESADA';
$link = 'index.php?option=com_mercurio&view=planilla';
}
//$model->checkin();
$this->setRedirect($link, $msg);
}
}
This is the model:
$cliente = new SoapClient(URLMERCURIOWS.URLWSPLANILLA, array('login'=>LOGINWS,'password'=>PASSWORDWS));
if (is_soap_fault($cliente)) {
trigger_error("SOAP Fault: (faultcode: {$arr->faultcode}, faultstring: {$arr->faultstring})", E_USER_ERROR);
return false;
}
$postost = JRequest::get( 'post', JREQUEST_ALLOWHTML );
$postost['cdPoblacionOrigen'] = JRequest::getVar('cdPoblacionOrigen', '', 'post', 'cdPoblacionOrigen');
$postost['nmSecDniCliente'] = JRequest::getVar('nmSecDniCliente', '', 'post', 'nmSecDniCliente');
$postost['cdAgenciaCliente'] = JRequest::getVar('cdAgenciaCliente', '', 'post', 'cdAgenciaCliente');
$postost['nmPesoTransportado'] = JRequest::getVar('nmPesoTransportado', '', 'post', 'nmPesoTransportado');
$postost['nmVolumenTransportado'] = JRequest::getVar('nmVolumenTransportado', '', 'post', 'nmVolumenTransportado');
$postost['nmUndsTransportadas'] = JRequest::getVar('nmUndsTransportadas', '', 'post', 'nmUndsTransportadas');
$planilla = array();
$planilla = $postost;
echo $postost['cdPoblacionOrigen']."</br>";
echo $postost['nmSecDniCliente']."</br>";
echo $postost['cdAgenciaCliente']."</br>";
echo $postost['nmPesoTransportado']."</br>";
echo $postost['nmVolumenTransportado']."</br>";
echo $postost['nmUndsTransport开发者_JAVA百科adas']."</br>";
$cliente->ingresarPlanilla( AGENCIAXDEFECTO, null, null, null, $postost['cdPoblacionOrigen'], $post['nmSecDniCliente'], $post['cdAgenciaCliente'], null, $post['nmPesoTransportado'], $post['nmVolumenTransportado'], $post['nmUndsTransportadas'], null, null, null, null, null, null, null, null, null);
return true;
}
This is the view:
<form id="ingresarPlanilla" name="ingresarPlanilla" method="post" action="?option=com_mercurio&view=planilla&controller=planilla&task=add">
<table width="98%" border="1" bordercolor="#ECE9D8">
<tr>
<td width="21%" class="titulo" align="center">Ingresar Planilla</td>
<td width="29%"> </td>
<td width="21%"> </td>
<td width="29%"> </td>
</tr>
<tr>
<td colspan="2">Agencia Origen</td>
<td colspan="2"><input name="cdAgenciaOrigen" type="text" class="campo_noeditable" id="cdAgenciaOrigen" value="<?php echo AGENCIAXDEFECTO;?>"readonly="readonly"/></td>
</tr>
<tr>
<td colspan="2">Poblacion Origen</td>
<td colsp man="2"><input name="cdPoblacionOrigen" type="text" class="campo" id="cdPoblacionOrigen" /></td>
</tr>
<tr>
<td colspan="2">DNI Cliente</td>
<td colspan="2"><input name="nmSecDniCliente" value="<?php echo $aux[5];?>" type="text" class="campo" id="nmSecDniCliente"/></td>
</tr>
<tr>
<td colspan="2">Peso Transportado</td>
<td colspan="2"><input name="nmPesoTransportado" type="text" class="campo" id="nmPesoTransportado "/></td>
</tr>
<tr>
<td colspan="2">Volumnen Transportado</td>
<td colspan="2"><input name="nmVolumenTransportado" type="text" class="campo" id="nmVolumenTransportado"/></td>
</tr>
<tr>
<td colspan="2">Unidades Transportados</td>
<td colspan="2"><input name="nmUndsTransportadas" type="text" class="campo" id="nmUndsTransportadas"/></td>
</tr>
<tr>
<td colspan="3">Observaciones</td>
</tr>
<tr>
<td colspan="3"><textarea name="observaciones" cols="60" rows="3" class="campo" id="observaciones"></textarea></td>
</tr>
<tr>
<td class="label"><input type="submit" name="Enviar" id="Enviar" value="Enviar" /></td>
</tr>
<input type="hidden" name="option" value="com_mercurio" />
<input type="hidden" name="cdAgenciaCliente" value="<?php echo $aux[6];?>" />
<input type="hidden" name="view" value="<?php echo JRequest::getVar('view'); ?>" />
<input type="hidden" name="task" value="" />
<?php echo JHTML::_( 'form.token' ); ?>
You can use this line below to read all POST data into an array with key value pairs.
$post = JRequest::get('post');
This will load all values into an array. So you would use the above like so:
$post = JRequest::get('post');
echo $post['cdPoblacionOrigen']; // prints value of post for input with name 'cdPoblacionOrigen'
精彩评论