Me he encontrado con un problema a la hora de hacer los tests del
proyecto que estoy realizando con cake 1.1.x, el problema es el
siguiente, con IE5.5 e IE5.0 cuando tenemos un formulario realizado
mediante ajax->form al enviarlo el controlador el $this-
>RequestHandler->isAjax() detecta que lo hemos enviado mediante Ajax,
sin embargo no envía la información. es decir $this->data está
vació...
Mi solución... irme a la API, para controlar cuando el navegador es
uno de estos y entonces hacer que el formulario no sea enviado por
ajax. Quedaría algo como esto:
en cake/libs/view/helpers/html.php sustituimos la funcion formTag por
esta otra:
function formTag($target = null, $type = 'post', $htmlAttributes =
array()) {
$navegadores = array(
'IE5' => '(MSIE 5\.[0-4]+)',
'IE5.5' => '(MSIE 5\.[5-9]+)',
'IE4' => '(MSIE 4\.[0-9]+)',
);
foreach($navegadores as $navegador=>$pattern){
if (eregi($pattern, $_SERVER['HTTP_USER_AGENT']))
$nav= $navegador;
}
if(!isset($nav)){
$nav="Otro";
}
$htmlAttributes['action']=$this->urlFor ($target);
$htmlAttributes['method']=$type == 'get' ? 'get' : 'post';
$type == 'file' ? $htmlAttributes['enctype'] = 'multipart/form-
data' : null;
$append = '';
if (isset($this->params['_Token']) && !empty($this-
>params['_Token']) && $nav!="IE5" && $nav!="IE5.5" && $nav!="IE4") {
//$append .= '<p style="display: inline;
margin: 0px; padding:
0px;">';
$append .= $this->hidden('_Token/key',
array('value' => $this-
>params['_Token']['key'], 'id' => '_TokenKey' . mt_rand()), true);
//$append .= '</p>';
}
$v= sprintf($this->tags['form'], $this-
>parseHtmlOptions($htmlAttributes, null, '')) . $append;
if($nav=="IE5" || $nav=="IE5.5" || $nav=="IE4"){
$v=str_replace('onsubmit="return false;"','',$v);
}
return $v;
}
En cake/libs/view/helpers/ajax.php sustituimos la funcion form por
esta otra:
function form($params = null, $type = 'post', $options = array()) {
if (is_array($params)) {
extract($params, EXTR_OVERWRITE);
if (!isset($action)) {
$action = null;
}
if (!isset($type)) {
$type = 'post';
}
if (!isset($options)) {
$options = array();
}
} else {
$action = $params;
}
$htmlOptions = $this->__getHtmlOptions($options);
$htmlOptions['action'] = $action;
if (!isset($htmlOptions['id'])) {
$htmlOptions['id'] = 'form' . intval(rand());
}
$htmlOptions['onsubmit']="return false;";
if (!isset($options['with'])) {
$options['with'] =
"Form.serialize('{$htmlOptions['id']}')";
}
$options['url']=$action;
$v= $this->Html->formTag($htmlOptions['action'], $type,
$htmlOptions);
if(strpos($v,'onsubmit="return false;"'))
$v.= $this->Javascript->event("'" . $htmlOptions['id'].
"'",
"submit", $this->remoteFunction($options));
return $v;
}
Esta es mi solución, a ver si alguien tiene otra mejor, o hay alguna
manera de hacerlo sin modificar la API pues es algo que no me gusta
demasiado.
Saludos
--~--~---------~--~----~------------~-------~--~----~
Has recibido este mensaje porque estás suscrito a Grupo "CakePHP-es" de Grupos
de Google.
Si quieres publicar en este grupo, envía un mensaje de correo
electrónico a [email protected]
Para anular la suscripción a este grupo, envía un mensaje a [EMAIL PROTECTED]
Para obtener más opciones, visita este grupo en
http://groups.google.com/group/CakePHP-es?hl=es.
-~----------~----~----~----~------~----~------~--~---