1 (edited by xavier.bonnave 2013-07-13 2:14:45 PM)

Topic: Problem with getFormValues

Hi,
I am doing a website working with xajax.
Everything works great on my local server.
I  subscribe a hosting on LWS.(http://www.lws.fr/)
Online, functions without form treatment works, but when I try a getFormValues it won't.
I have tried a simple code:


When i declare $string as a simple string like "hello", it works perfect. my string goes to the "box" id.
when I declare $string as $formValue['text-field'], "{" character  goes to the "box" id.
and when I test like the example, loop thinking...

Please help me!
Thank you so much

<?php

require_once('./xajax_core/xajax.inc.php');
$xajax = new xajax();
function myFunction($formValue)
{
if(array_key_exists("text-field",$formValue))
  {
   $string = $formValue['text-field'];
  }
  else
  {
   $string = 'no';
  }


  $objResponse = new xajaxResponse();

  $objResponse->assign("box","innerHTML",$string);
  return $objResponse;
}
$xajax->register(XAJAX_FUNCTION, 'myFunction');
$xajax->processRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <title>Hello!</title>
<?php $xajax->printJavascript();?>
<script type="text/javascript">
  function myFunction()
  {
    xajax_myFunction(xajax.getFormValues("test-form"));
  }
</script>
</head>

<body>


<div id="box">Here</div>
<form id="test-form" method="post">
    <input type="text" name="text-field" value="" />
    <input type="button" onClick="myFunction();" />
</form>

</body>

</html>

Re: Problem with getFormValues

Hi,

I have never experienced this problem locally or on a hosting server so it's a new one...

I see nothing in your code that should cause a problem with the possible exception of your not setting the javascript URI configuration value. If that were the issue you would see the message about not being able to load the javascript in the browser.

Have you tried the xajax debugger?

Have you tried using the respons object slert function to show you the form values received?

$resp->alert(print_r($formValues,true));

Do you have access to the apache error log on your host to see if anything is something is erroring out?

I will try your code on my host and get back...

Ed

Edit:

I tried your code locally and on my hosting server. I had to add the configuration "javascript URI" as my xajax is in the xajax folder but it worked fine locally and on my hosting server (bluehost.com). It soulds like som problem with the server settings.
Try the debugger and the alert and let m know.

<?php
require_once('xajax/xajax_core/xajax.inc.php');
$xajax = new xajax(); 
$xajax->configure('javascript URI', 'xajax/'); //My Edit
If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Problem with getFormValues

Hi, i'm having the same error, when I test it in my local works fine, but when i test it in the server i get a "}" in  xjxobj data, I used firebug and I get this in the response:

{"xjxobj":[{"cmd":"al","data":"{"},{"cmd":"al","data":"select * FROM necesidades where campana={ and plaga!= 0 "}]}

this is my code:

function llena_select_P($form_entrada){
  $respuesta = new xajaxResponse();
  $isCampana=$form_entrada["campana"];
  $idCampanaArray=explode(",", $isCampana);
  $idCampana=$idCampanaArray[0];


  $ssql="select * FROM necesidades where campana=".$idCampana." and plaga!= 0 ;
  $result = mysql_query($ssql)  or die (mysql_error()) ;
    return $respuesta;
}

and in my html

            <select name="campana" id="campana"  onchange="xajax_llena_select_P(xajax.tools.getFormValues('formulario'));">

Re: Problem with getFormValues

What version of xajax and php are you using?

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

Re: Problem with getFormValues

Hi,

First, excuse-me for my english. It's not very well...

I've got the same problem with getFormValues.
My script (a log script) is working on one of my server, but it's not on an other.

I made some tests:

In the first case (no problem), getFormValues return an Array:

Array (
[login] => "Thierry"
[password] => "Thierry64"
)

In the second case (here is the problem), getFormValues return a string:

{"login":"Thierry","password":"Thierry64"}

The problem seems to result from an incompatibility with my server (or some settings) and xAjax.

Is someone has the solution?

Thanks a lot

Re: Problem with getFormValues

Hi,

try using json_decode() on it to get an array.

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

Re: Problem with getFormValues

Hi,

When I try json_decode(), getformValues returns NULL.

Re: Problem with getFormValues

use json decode in the php code...

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

Re: Problem with getFormValues

Hi,
The error occurs on the server settings in the policy:
  * magic_quotes_gpc with the value "on"

To solve it we include in .htacces file the following.:
  * php_value magic_quotes_gpc off

And ready