Topic: xajax.getFormValues not pass variables PHP 5.4

Java Script Code

function adicionarModalidades() {

    var modalidades = CKEDITOR.instances['descricao']; if (modalidades) { CKEDITOR.remove(CKEDITOR.instances['descricao']); }   

    xajax_listagemCadModalidadesAcoes('incluir', null, xajax.getFormValues('modalidadesAdiciona',true),modalidades.getData());
   
}

###############

Form Code
       
                        <table align="center" border="0" cellspacing="0" cellpadding="0" class="conteudoLayoutCadUsu">
                          <tr background="imagens/layout/pdr_conteudo_sup_fundo.gif">
                            <td class="conteudoLayoutCargaEsq"><img src="imagens/layout/pdr_conteudo_canto_sup_esq.gif" width="17" height="20"></td>
                            <td background="imagens/layout/pdr_conteudo_sup_fundo.gif"></td>
                            <td class="conteudoLayoutCargaDir"><img src="imagens/layout/pdr_conteudo_canto_sup_dir.gif" width="17" height="20"></td>       
                          </tr>
                          <tr>
                            <td width="17px" class="conteudoLayoutCargaEsq"><img src="imagens/layout/pdr_conteudo_fundo_esq.gif" /></td>
                            <td class="conteudoLayoutCargaMeio">
                                <div id="conteudoLayoutCadUsuErro" class="conteudoLayoutCadUsuErro" style="display: none;"></div>
                                <div id="cargaConteudoLayout" style="width: 600px;">
                                    <form id="modalidadesAdiciona" onsubmit="return false;">
                                        <p>Titulo Modalidade: <input maxlength="250" type="text" name="galeria[tit]" id="tit" value=""></p>
                                        <p><label for="conteudo">Descricao Modalidade: </label><textarea id="descricao" name="descricao" rows="45" cols="80" style="width: 100%;" tabindex=2></textarea></p>                                                                                       

                                        <br>
                                        <p><a href="#" class="btn" onClick="adicionarModalidades();">Cadastrar</a></p>
                                    </form>
                                </div>   
                            </td>
                            <td width="17px" class="conteudoLayoutCargaDir"><img src="imagens/layout/pdr_conteudo_fundo_dir.gif" /></td>
                          </tr>
                          <tr background="imagens/layout/pdr_conteudo_inf_fundo.gif">
                            <td><img src="imagens/layout/pdr_conteudo_canto_inf_esq.gif" width="17" height="20"></td>
                            <td background="imagens/layout/pdr_conteudo_inf_fundo.gif"></td>
                            <td><img src="imagens/layout/pdr_conteudo_canto_inf_dir.gif" width="17" height="20"></td>
                          </tr>
                        </table>

##############

Xajax Code

function listagemCadModalidadesAcoes($acao=null,$id=null,$dados=null,$descricao=null){
    include("Conteudo.php");
    $objResponse = new xajaxResponse();
    $ajax = new Ajax();
    $cont = new Conteudo();
    $banco = new Banco();
    $funcao = new Funcoes();
   
    $usuarioLogado = $ajax->VerificaAcesso();
    if ( ($usuarioLogado == true) or ($usuarioLogado == "true") ) {
        if ($acao == "adicionar") {
            if($ajax->VerificaPermissao($cont->menuModulo, $cont->menuModuloOpcao, "inserir")) {
                $conteudo = $cont->modalidadesAdicionar();           
                $objResponse->assign("cargaConteudo","innerHTML","$conteudo");   
                $objResponse->assign("cargaConteudoTitulo","innerHTML","Adicionar uma Modalidade");
                $objResponse->call("btn.init");
                $objResponse->call("carregarBarraFromatacaoModalidades");
            } else {
                $objResponse->alert("Você não tem a permissão necessária para realizar essa operação!");
            }
        } elseif ($acao == "alterar") {
            if($ajax->VerificaPermissao($cont->menuModulo, $cont->menuModuloOpcao, "atualizar")) {               
                $conteudo = $cont->modalidadesAlterar($id);           
                $objResponse->assign("cargaConteudo","innerHTML","$conteudo");   
                $objResponse->assign("cargaConteudoTitulo","innerHTML","Alterar esta Modalidade");
                $objResponse->call("btn.init");
                $objResponse->call("carregarBarraFromatacaoModalidades");               
            } else {
                $objResponse->alert("Você não tem a permissão necessária para realizar essa operação!");
            }                                   
        } elseif ($acao == "incluir") {
            if($ajax->VerificaPermissao($cont->menuModulo, $cont->menuModuloOpcao, "inserir")) {       
                $erroPreenchimento = "";
                if (trim($dados['galeria']['tit']) == "") $erroPreenchimento.= "<label>Preencha o Titulo</label>";
                if (trim($erroPreenchimento) == "") {                                   
                   
                    if (trim($erroPreenchimento) == "") {

                        # REMOVE OS ESPAÇO DESNECESSÁRIOS
                        if ($dados["galeria"])
                            foreach ($dados["galeria"] as $index => $valor)                               
                        $dados["galeria"][$index] = trim(stripslashes($valor));
                       
                        $dados["galeria"]["tit"] = str_replace("'","&#39;", $dados["galeria"]["tit"]);   
                        $dados["galeria"]["descricao"] = str_replace("'","&#39;",stripslashes($descricao));
                        $dados["galeria"]["noticia_datacadastro"] = date("Y-m-d H:i:s");
                        $dados["galeria"]["noticia_dataatualizacao"] = date("Y-m-d H:i:s");   
                       
                        $banco->inserirRegistro(CONEXAO, "modalidades", $dados["galeria"]);
                       
                        $objResponse->assign("conteudoLayoutCadUsuErro","style.display","none");   
                        $objResponse->assign("cargaConteudoLayout","innerHTML","<img src=\"imagens/icones/ok_30_30.png\" align=\"absmiddle\">&nbsp;&nbsp;Modalidade adicionada com sucesso");                           

                    } else {
                        $objResponse->assign("conteudoLayoutCadUsuErro","innerHTML","$erroPreenchimento");
                        $objResponse->assign("conteudoLayoutCadUsuErro","style.display","block");                   
                    }
                } else {
                    $objResponse->assign("conteudoLayoutCadUsuErro","innerHTML","$erroPreenchimento");
                    $objResponse->assign("conteudoLayoutCadUsuErro","style.display","block");   
                }
            } else {
                $objResponse->alert("Você não tem a permissão necessária para realizar essa operação!");
            }               
        } elseif ($acao == "atualizar") {
            if($ajax->VerificaPermissao($cont->menuModulo, $cont->menuModuloOpcao, "atualizar")) {       
                $erroPreenchimento = "";
                if (trim($dados['galeria']['tit']) == "") $erroPreenchimento.= "<label>Preencha o Titulo</label>";
                if (trim($erroPreenchimento) == "") {               

                    if (trim($erroPreenchimento) == "") {
                   
                       
                        if ($dados["galeria"])
                            foreach ($dados["galeria"] as $index => $valor)                               
                                $dados["galeria"][$index] = trim(stripslashes($valor));
                       
                        $dados["galeria"]["tit"] = str_replace("'","&#39;", $dados["galeria"]["tit"]);
                        $dados["galeria"]["descricao"] = str_replace("'","&#39;",stripslashes($descricao));
               
                       
                               
                        $banco->alterarRegistro(CONEXAO, "modalidades", "id_galeria", $dados['galeria']['id_galeria'], $dados["galeria"]);

                        $objResponse->assign("conteudoLayoutCadUsuErro","style.display","none");   
                        $objResponse->assign("cargaConteudoLayout","innerHTML","<img src=\"imagens/icones/ok_30_30.png\" align=\"absmiddle\">&nbsp;&nbsp; Modalidade atualizada com sucesso");                           

                    } else {
                        $objResponse->assign("conteudoLayoutCadUsuErro","innerHTML","$erroPreenchimento");
                        $objResponse->assign("conteudoLayoutCadUsuErro","style.display","block");                   
                    }
                } else {
                    $objResponse->assign("conteudoLayoutCadUsuErro","innerHTML","$erroPreenchimento");
                    $objResponse->assign("conteudoLayoutCadUsuErro","style.display","block");   
                }
            } else {
                $objResponse->alert("Você não tem a permissão necessária para realizar essa operação!");
            }                           
        } elseif ($acao == "excluir") {
            if($ajax->VerificaPermissao($cont->menuModulo, $cont->menuModuloOpcao, "excluir")) {       
           
                $banco->excluirRegistro(CONEXAO, "modalidades", "id_galeria", $id);
           
                $sql = "SELECT * FROM modalidades_imagem WHERE id_galeria = ".$id;
                //$objResponse->alert($sql);
                $dadosRetorno = $banco->montaVetor($banco->executaSql(CONEXAO, $sql));
                if (count($dadosRetorno) > 0)
                foreach ($dadosRetorno as $d) {
                    $banco->excluirRegistro(CONEXAO, "modalidades_imagem", "id_galeria_imagem", $d["id_galeria_imagem"]);                           
                    unlink("../../../images/modalidades/thumbs/".$d["img"]);
                    unlink("../../../images/modalidades/site/".$d["img"]);
                    unlink("../../../images/modalidades/lista/".$d["img"]);
                }

                $objResponse->alert("Modalidade excluída com sucesso!");
                $objResponse->call("CarregarCadModalidades()");
               
            } else {
                $objResponse->alert("Você não tem a permissão necessária para realizar essa operação!");
            }                           
        } else {
            $objResponse->assign("cargaConteudo","innerHTML","<center>Ação que tentou realizar é inválida para o sistema.</center>");   
            $objResponse->assign("cargaConteudoTitulo","innerHTML","Erro");       
        }
    } else {
        $objResponse->call("AtualizarPagina");   
    }
    return $objResponse;   
}

##############

Xajax Debug Code

xajax debug output

Fri Dec 13 2013 00:55:34 GMT-0300 (BRT)
DONE [610ms]
Fri Dec 13 2013 00:55:34 GMT-0300 (BRT)
RECEIVED [status: 200, size: 202 bytes, time: 609ms]:
{"xjxobj":[{"cmd":"as","id":"conteudoLayoutCadUsuErro","prop":"innerHTML","data":"<label>Preencha o Titulo<\/label>"},{"cmd":"as","id":"conteudoLayoutCadUsuErro","prop":"style.display","data":"block"}]}
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
SENT [176 bytes]
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
SENDING REQUEST
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
CALLING:
xjxfun: listagemCadModalidadesAcoes
URI:
ajax.rotinas.php
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
POST: xjxfun=listagemCadModalidadesAcoes
&xjxr=1386906933786
&xjxargs[]=Satualizar
&xjxargs[]=*
&xjxargs[]={"galeria":[],"descricao":"dasdsa"}   ***  ==>>> *** here in this line shows that he did not pass the variable "galeria[tit]" ***
&xjxargs[]=Sdasdsa
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
PREPARING REQUEST
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
PROCESSING PARAMETERS [4]
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
INITIALIZING REQUEST
Fri Dec 13 2013 00:55:33 GMT-0300 (BRT)
STARTING XAJAX REQUEST

xajax.getFormValues not pass variables PHP 5.4

Re: xajax.getFormValues not pass variables PHP 5.4

Try changing this: name="galeria[tit]" id="tit" value=""

to this: name="galeria['tit']" id="tit" value=""

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

3 (edited by renatoandrade.com 2013-12-13 8:44:08 PM)

Re: xajax.getFormValues not pass variables PHP 5.4

It did not work, have another solution?

Is there any problem in multidimensional array with field name=input[variable] in xajax 0.6 with php 5.4? I believe the problem must be it.

Re: xajax.getFormValues not pass variables PHP 5.4

Not that I know of. I'll look some more...

Have you tried this: name="galeria[]" id="tit" value=""

What is the purpose of the array syntax galeria[tit]?

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: xajax.getFormValues not pass variables PHP 5.4

It is because I have other modules that have multiple fields rather than keep doing parameters I pass all parameters directly.

6 (edited by renatoandrade.com 2013-12-14 8:38:37 AM)

Re: xajax.getFormValues not pass variables PHP 5.4

It did not work, have another solution?

I took out the "gallery[tit]" and only left the field and went normal believe it will not accept it as older versions of xajax, the 0:25 version 0.5 and normally accept, but the php 5.4 does not run these 2 versions, the fields do not pass parameter name="gallery[tit]" but the parameter that way he passes name="tit"


Debug

POST: xjxfun=listagemCadModalidadesAcoes
&xjxr=1387006698905
&xjxargs[]=Satualizar
&xjxargs[]=*
&xjxargs[]={"id_galeria":"5","tit":"Testando Alterações","descricao":"Testando Alterações Descrição"}
&xjxargs[]=STestando Altera&ccedil;&otilde;es Descri&ccedil;&atilde;o

Re: xajax.getFormValues not pass variables PHP 5.4

Well, we lost that one...

I assume that you understand that it is the xajax client side javascript that you are dealing with and not the php.

BTW, the changes from php 5.3 to 5.4 should not have an effect on the xajax php code.

I only have php 5.3 and xajax 0.6 works well...

I'll look some more and maybe try some sample code.

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: xajax.getFormValues not pass variables PHP 5.4

So, I have had a realization that might help.

getFormValues uses the name and not the id values. So using an array syntax in the id is of no value.
Neither does putting an alpha value in the brackets.



You can put a number in the brackets and you get a zero based array.

It doesn't work if there is an alpha value within the brackets. Then it submits something like you have been seeing.

I think it might be a javascript issue. I'll look at the xajax javascript.

This code works submitting an array named field.

<?php
/**
 * 2013-12-14
 * Trying out html name array
 */
//Setup the xajax framework.
include_once("xajax6/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure('debug',true);
$xajax->configure('javascript URI', 'xajax6/');

function processForm($data)
{
  $resp = new xajaxResponse();
  $resp->alert(print_r($data,true));
  return $resp;
}

$xajax->register(XAJAX_FUNCTION,'processForm');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<?php $xajax->printJavascript() ?>
</head>
<body>
<form id="form1">
<input id="field1" name="field[]" value="field1val"/><br/>
<input id="field2" name="field[]" value="field2val"/><br/>
<input type="button" value="Submit" onclick="xajax_processForm(xajax.getFormValues('form1'))"/>
</form>
</body>
</html>

Could you show how you populate the brackets?

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: xajax.getFormValues not pass variables PHP 5.4

After shopping around it seems this might be an xajax 0.6 javascript issue.

If I use xajax 0.5 and alpha array indexes it works fine...

I'll investigate and see if it can be repaired.

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: xajax.getFormValues not pass variables PHP 5.4

Found a fix on the forum. Involved a couple of small changes to xajax_core.js

I will mail you a zip file

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

11 (edited by renatoandrade.com 2013-12-16 8:22:46 PM)

Re: xajax.getFormValues not pass variables PHP 5.4

That's what I saw my friend, Javascript version 0.6 is in trouble, version 0.5 works perfectly, if they can fix this I would appreciate it, would they give a very good analyzed in the new code, the way the developers stopped making new versions ? The project is stopped? Thank you for your attention, you have helped me a lot. Thank you!

Re: xajax.getFormValues not pass variables PHP 5.4

So you got my email and it works as expected?

Is there anything else?

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

13 (edited by renatoandrade.com 2013-12-17 12:14:40 AM)

Re: xajax.getFormValues not pass variables PHP 5.4

Thanks, it worked 100%, I am too grateful for your help, you will update the file download within the community? will now leave him available for personal download?

Mon Dec 16 2013 20:14:13 GMT-0300 (BRT)

Debug Code
POST: xjxfun=listagemCadGaleriaAcoes
&xjxr=1387235653259
&xjxargs[]=Satualizar
&xjxargs[]=*
&xjxargs[]={"galeria":{"id_galeria":"8","tit":"test","tit_home":"test2"},"descricao":"teste desc"}
&xjxargs[]=Stest description

Re: xajax.getFormValues not pass variables PHP 5.4

I have instituted a pull request for the xajax project on GitHub. Not sure we'll hear from any of the other folks bur we'll see...

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

15 (edited by renatoandrade.com 2013-12-17 12:38:35 AM)

Re: xajax.getFormValues not pass variables PHP 5.4

You did change the code in line 90 xajax_core.js ?

aFormValues[k]=[];var p=aFormValues;while(a.length!=0){var sa=a.substr(0,a.indexOf(']')+1);var lk=k;var lp=p;a=a.substr(a.indexOf(']')+1);p=p[k];k=sa.substr(1,sa.length-2);if(k==''){if('select-multiple'==child.type){k=lk;p=lp;}else{k=p.length;}
}
if(typeof p[k]=='undefined')
p[k]=[];}

For change to
aFormValues[k]=a=='[]' ? []:{};var p=aFormValues;while(a.length!=0){var sa=a.substr(0,a.indexOf(']')+1);var lk=k;var lp=p;a=a.substr(a.indexOf(']')+1);p=p[k];k=sa.substr(1,sa.length-2);if(k==''){if('select-multiple'==child.type){k=lk;p=lp;}else{k=p.length;}
}
if(typeof p[k]=='undefined')
p[k]=a=='[]' ? []:{};}

Re: xajax.getFormValues not pass variables PHP 5.4

in the uncompressed the changes are at 874 and 895

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.