Topic: Extended getFormValues(...)

Hello,

I have a HTML-page which contains a lot of inputfields. If the user push the button "submit", I send
the userfields to the server. The problem is, that I have to know which fields are deactivated/activated (on the Server).
Here you see my problem:

<html>
...
<form id="properties">
<input type="text" ...>
<input type="button" onclick="xajax_do(xajax.getFormValues('properties', true), xajax.getFormValues('properties', false)); return false;">
</form>

This code do the job, but when I have 100 inputfields, I send 100 inputfields for all properties and
about 80 for the activated properties to the server. But I need a method, which sends 100 inputfields with the
Attributes "deactivated/activated" to the server.



The new idea:

html:
-----
<html>
<form id="properties">
<input type="text" id="input_1" name="input_1">
<input type="text" id="input_2" name="input_2" disabled="disabled">
<input type="button" onclick="xajax_do(xajax.getExtendedFormValues('properties')); return false;">
</form>

php:
----
function do($aFields)
{
    var_dump($aFields);
}

Output:
-------
array(
"__formname"=>"properties",
"input_1"=>array("content", true), // activated
"input_2"=>array("content", false) // deactivated
);


Is that possible, or exists another alternative???

Re: Extended getFormValues(...)

As an alternative you could use a javascript hack (barely tested, only deals with simple cases) like this:

<script type="text/javascript">
function getFormValuesDisabled(parent) {
    var aFormValues = xajax.getFormValues(parent, true);
    if ('string' == typeof parent) parent = xajax.$(parent);
    var aFormValuesDisabled = {};
    for (var key in aFormValues) {
        aFormValuesDisabled[key] = [aFormValues[key], parent[key] && parent[key].disabled];
    }
    return aFormValuesDisabled;
}
</script>

Re: Extended getFormValues(...)

I don't know if this will help but getFormValues has a second boolean parameter that specifys whether or not to send disabled controls.

i.e xajax.getFormValues('myForm', false)

Ed

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

Re: Extended getFormValues(...)

Thanks for your responses.

@dickdoc
Your script seems to be OK, but you see, that this functionality is missing in the XAJAX-Framework.

@Ed
At the moment I use this method with the additional parameter!
See my first post: <input type="button" onclick="xajax_do(xajax.getFormValues('properties', true), xajax.getFormValues('properties', false)); return false;">

But the problem is, that I have to know which field is disabled and his value. With my posted method I send the
data 2 two times! First all data (activated/deactivated) and at the second part only the activated. I have a mask
with !100! inputfields. Now I send 100 activated/deactivated inputfields with data and about 80 activated inputfields with data(see the code).
That means, that I send the same data two times to reach my aim. My system is a productive-system. Every BYTE is too much. You see my problem? The problem is the data-volume!!!

@admins / programmers
Is it possible (in the future) to implement a new form-method like

html:
-----
<html>
<form id="properties">
<input type="text" id="input_1" name="input_1">
<input type="text" id="input_2" name="input_2" disabled="disabled">
<input type="button" onclick="xajax_do(xajax.getExtendedFormValues('properties')); return false;">
</form>

php:
----
function do($aFields)
{
    var_dump($aFields);
}

Output:
-------
array(
"__formname"=>"properties",
"input_1"=>array("content", true), // activated
"input_2"=>array("content", false) // deactivated
);

Re: Extended getFormValues(...)

OK. How about the PHP arrai_diff_key() function?

<?php
/*
    Trying array_diff_key();
*/
function properties($allfields, $activefields)
{
    //Assuming these values in the passed arrays:
    $allfields = array(a=>'a', b=>'b', c=>'c', d=>'d');
    $activefields = array(a=>'a', d=>'d');
    //Returns b=>'b' and c=>'c' from the allfields array. 
    //These are the disabled fields
    $disabledfields = array_diff_key($allfields, $activefields);
    
    print_r($disabledfields);
}
?>

Ed

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

Re: Extended getFormValues(...)

Hey ed,

thx for your posts, but I believe you don't understand my problem. Please read the last post:

bonkaehlchen wrote:

Thanks for your responses.
@Ed
At the moment I use this method with the additional parameter!
See my first post: <input type="button" onclick="xajax_do(xajax.getFormValues('properties', true), xajax.getFormValues('properties', false)); return false;">

But the problem is, that I have to know which field is disabled and his value. With my posted method I send the
data 2 two times! First all data (activated/deactivated) and at the second part only the activated. I have a mask
with !100! inputfields. Now I send 100 activated/deactivated inputfields with data and about 80 activated inputfields with data(see the code).
That means, that I send the same data two times to reach my aim. My system is a productive-system. Every BYTE is too much. You see my problem? The problem is the data-volume!!!

At the moment, I use this method:

<input type="button" onclick="xajax_do(xajax.getFormValues('properties', true), xajax.getFormValues('properties', false));"

That is the same method as yours!!!

But see: I have 100 Inputfields and send 180 Inputfields with data to the server. You see the problem? The data-volume!!!

Re: Extended getFormValues(...)

I understand your problem. We're just trying to provide a workaround.

I tried dickdock's JS in the following and it appears to provide what you are looking for:

<?php
/*
    Attempt to implement an extended getFormValues() that 
    returns an indication of whether or not an element is 
    disabled.
    
    Using the JS posted by dickdock on the XAJAX forum.
*/
require_once("xajax/xajax_core/xajax.inc.php"); 
$xajax = new xajax();                                                     

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

$xajax->register(XAJAX_FUNCTION,'test');
$xajax->processRequest();
?>
<html>
<head>
<? $xajax->printJavascript('xajax'); ?>

<script type="text/javascript">
function getFormValuesDisabled(parent) {
    var aFormValues = xajax.getFormValues(parent, true);
    if ('string' == typeof parent) parent = xajax.$(parent);
    var aFormValuesDisabled = {};
    for (var key in aFormValues) {
        aFormValuesDisabled[key] = [aFormValues[key], parent[key] && parent[key].disabled];
    }
    return aFormValuesDisabled;
}
</script>
</head>
<body>
<form id='form1'>
<input id="in1" name="in1" value="1" disabled>
<input id="in2" name="in2" value="2" disabled>
<input id="in3" name="in3" value="3" />
<input id="in4" name="in4" value="4" />
<input type="button" value="Click Me" onclick="xajax_test(getFormValuesDisabled('form1'));">
</form>
</body>
</html>

The array contains each element's name, its value and an indication of whether it is disabled or not. Looks like a keeper to me...:)

Ed

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

Re: Extended getFormValues(...)

Another possible solution would be to scan the form and return the name of each field that is (either) enabled (or disabled) to your method as the second parameter.

listEnabled = function(frmName) {
... 
}
...
<form ... onsubmit='xajax_do(xajax.getFormValues("theForm"), listEnabled("theForm")); return false;'>
...
function do($formValues, enabled) {
...
}

// Joe

xajax Developer
Connect to me on LinkedIn:
http://www.linkedin.com/in/calledtoconstruct