Topic: Help to correct

<?php
require_once("../xajax_core/xajax.inc.php");

function testForm($formData)
{
    $objResponse = new xajaxResponse();
   
    exit('<pre>'. print_r ($formData, true).'</pre>');

    return $objResponse;
}

$xajax = new xajax();
$xajax->configure("debug", true);
$xajax->register(XAJAX_FUNCTION, "testForm");
$xajax->processRequest();
$xajax->configure('javascript URI','../');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/2000/REC-xhtml1-20 … tional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>xajax Tests</title>
<?php $xajax->printJavascript("../") ?>
</head>
<body>

<h2><a href="index.php">xajax Tests</a></h2>
<h1>Disabled Form Elements Test</h1>

<form id="testForm1" onsubmit="return false;">
<textarea value="10" id="description" name="description[10]" maxlength="128" cols="10" rows="4">100</textarea><br>
<textarea value="20" id="description" name="description[20]" maxlength="128" cols="10" rows="4">200</textarea><br>
<a onclick="xajax_testForm(xajax.getFormValues('testForm1')); return false;">save</a>
</form>
<div id="submittedDiv"></div>

</body>
</html>


quit

<pre>Array
(
    [description] => Array
        (
            [0] =>
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] =>
            [6] =>
            [7] =>
            [8] =>
            [9] =>
            [10] => 100
            [11] =>
            [12] =>
            [13] =>
            [14] =>
            [15] =>
            [16] =>
            [17] =>
            [18] =>
            [19] =>
            [20] => 200
        )

)
</pre>

And it is necessary that was or

Here it is necessary for me

<pre>Array
(
    [description] => Array
        (
            [10] => 100
            [20] => 200
        )

)
</pre>

Re: Help to correct

Hi,

I tried your code with xajax 0.5 and it works ok. I got the same result you did with xajax 0.6...

I messed with your code a bit and came up with this:

<?php
require_once("xajax0.6b/xajax_core/xajax.inc.php");
function testForm($formData)
{
    $objResponse = new xajaxResponse();
    $var = print_r($formData,true);
    $objResponse->alert($var);
    return $objResponse;
}
$xajax = new xajax();
//$xajax->configure("debug", true);
$xajax->register(XAJAX_FUNCTION, "testForm");
$xajax->configure('javascript URI','xajax0.6b/');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<title>xajax Tests</title>
<?php $xajax->printJavascript() ?>
</head>
<body>
<h2><a href="index.php">xajax Tests</a></h2>
<h1>Disabled Form Elements Test</h1>
<form id="testForm1" onsubmit="return false;">
<textarea id="description[]" name="description[]" maxlength="128" cols="10" rows="4">100</textarea><br>
<textarea id="description[]" name="description[]" maxlength="128" cols="10" rows="4">200</textarea><br>
<input type="button" value="Save"onclick="xajax_testForm(xajax.getFormValues('testForm1'))";/>
</form>
<div id="submittedDiv"></div>
</body>
</html>

This works ok giving [0] and [1] so it looke like something in 0.6

If I put any values in the array subscripts it sends from zero to the highest subscript element  as you have seen.

The getFormvalues() function uses the name attribute of the form elements. Seems to be the only function that does...

If you need to identify each of the textareas use a unique name for each of them. Also, you do not need an id attribute for the form elements unless you are going to assign something to them. Again, if you are going to populate them it would be best to use unique id values.

Hope this helps...
Ed

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

Re: Help to correct

edrobinson, The code turns out such

Array
(
    [description] => Array
        (
           [0] => 100
           [1] => 200
        )

)

And it is necessary for me

Array
(
    [description] => Array
        (
            [10] => 100
            [20] => 200
        )

)

Re: Help to correct

OK. Try this...

<?php
require_once("xajax0.6b/xajax_core/xajax.inc.php");
function testForm($formData)
{
    $objResponse = new xajaxResponse();
    $var = print_r($formData,true);
    extract($formData);
    $desc = array();
    for($i=0;$i<count($description);$i++)
    {
      if ($description[$i])
       $desc[$i] = $description[$i];
    }
    $desc = print_r($desc,true);
    $objResponse->alert($desc);
    return $objResponse;
}
$xajax = new xajax();
//$xajax->configure("debug", true);
$xajax->register(XAJAX_FUNCTION, "testForm");
$xajax->configure('javascript URI','xajax0.6b/');
$xajax->processRequest();
?>
<!DOCTYPE html>
<html>
<head>
<title>xajax Tests</title>
<?php $xajax->printJavascript() ?>
</head>
<body>
<h2><a href="index.php">xajax Tests</a></h2>
<h1>Disabled Form Elements Test</h1>
<form id="testForm1">
<textarea id="description[]" name="description[10]" maxlength="128" cols="10" rows="4">100</textarea><br>
<textarea id="description[]" name="description[20]" maxlength="128" cols="10" rows="4">200</textarea><br>
<input type="button" value="Save"onclick="xajax_testForm(xajax.getFormValues('testForm1'))";/>
</form>
<div id="submittedDiv"></div>
</body>
</html>

It only gives you the ones with a value.

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

Re: Help to correct

edrobinson. Thanks a lot, earned!

Re: Help to correct

i have tested this code and i see the same problem sad (on last version xajax from oficial site)

Array
(
    [description] => Array
        (
            [0] =>
            [1] =>
            [2] =>
            [3] =>
            [4] =>
            [5] =>
            [6] =>
            [7] =>
            [8] =>
            [9] =>
            [10] => 100
            [11] =>
            [12] =>
            [13] =>
            [14] =>
            [15] =>
            [16] =>
            [17] =>
            [18] =>
            [19] =>
            [20] => 200
        )

)

Re: Help to correct

The code I provided uses the latest xajax and only returns the elements of the textarea array that have values. smile

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

Re: Help to correct

latest xajax  from github (https://github.com/Xajax/Xajax) ?

Re: Help to correct

akonjakow, it laid out a working code. Xajax http://www.xajax-project.org/media/xaja … -beta1.zip