Topic: Form problem

Hello

I have the form with the following structure:


<input type="text" name="contact[Zip]" value="" size="8" maxlength="10">
<input type="text" name="contact[email]" value="" size="25" maxlength="60">, etc, etc, etc

I am not able to retrieve form values....

Please advise

Thank you

2 (edited by Doc 2008-03-14 11:35:08 AM)

Re: Form problem

Make sure the form has a id and then use the xajax.getFormValues(id) function for submitting the form.

Example

            <form id="signupForm" action="javascript:void(null);" onsubmit="xajax_processForm(xajax.getFormValues("signupForm"));">
                    <div>Username:</div><div><input type="text" name="username" /></div>
                    <div>Password:</div><div><input type="password" name="newPass1" /></div>
                    <div>Confirm Password:</div><div><input type="password" name="newPass2" /></div>
                    <div class="submitDiv"><input id="submitButton" type="submit" value="continue ->"/></div>
            </form>

Re: Form problem

Doc, my form has an id.
My problem is that i pass multi dimensional array into processForm(): (name="contact[email]").
I can't change it, and it is not working.

I'm wondering if there is a solution for this

Thanks

Re: Form problem

Vadim,

Try this:

[code]<?php
require_once ("xajax_0.5_beta4b/xajax_core/xajax.inc.php");
$xajax = new xajax();
function Testing($dta)
{

  $objResponse = new xajaxResponse();
  $objResponse->alert(print_r($dta,true));
  return $objResponse;
}
$xajax->setFlag('debug', true);
$xajax->registerFunction("Testing");  //Register the function
$xajax->processRequest();                //Call the XAJAX engine
?>[/code]
[code html]
<html>
<head>
  <?php $xajax->printJavaScript('xajax_0.5_beta4b'); ?>
</head>
<body>
<form id="form1">
<input type="text" name="contact[Zip]" value="" size="8" maxlength="10">
<input type="text" name="contact[email]" value="" size="25" maxlength="60">
<input type=button value="Send Form" onclick="xajax_Testing(xajax.getFormValues('form1'));">
</form>
</body>
</html>
[/code]

I believe this is like what Doc was talking about.

The alert shows the contact array from the form.

Ed

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

Re: Form problem

edrobinson, i have tried it - returns an empty array sad

and this problem only if the naming is in array format: name="info[email]"....

Re: Form problem

Vadim,

On my machine it returns an array named $dta[] which contains the array contact[].

Not sure what else to tell you...

I'll think about it  some.

Ed

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

Re: Form problem

Hi Vadim and ed wink

Sorry, but the lastest beta is a bit confusing when it's about multiple-select boxes. Please see this thread for further informations.

Re: Form problem

Hi q_no,

I don't get it... The inputs are text boxes not selects and their names are as array elements.

Here's what I receive in the PHP function $dta variable:   Array ( [contact] => Array ( [Zip] => aa [email]=> cc ) )

Seems like what one would expect - an array ($dta) containing another array (contact).

SHow me the light!:(

Ed

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

Re: Form problem

whoops ,  forget my post wink I was in a hurry and thought you were talking about multi-selectboxes and not about inputs using brakets[] in fieldnames....

Vadim, make sure that your html code is W3C valid, otherwise the getformvalues() function might not be able to retrieve all fields

Re: Form problem

Hi Ed

Sorry I know this post is very old so I hope you read this. I also rand the script you posted and all is well except when I try to echo the value. I have modify the script a little.

<?php
require_once ("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
function Testing($dta)
{
$newContent = <<<EOF_
$dta[contact][0]
EOF_;

  $objResponse = new xajaxResponse();
  $objResponse->assign("testDiv","innerHTML", $newContent);
  $objResponse->alert(print_r($dta,true));
  return $objResponse;
}
$xajax->setFlag('debug', true);
$xajax->registerFunction("Testing");  //Register the function
$xajax->processRequest(); //Call the XAJAX engine 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php $xajax->printJavaScript('xajax/'); ?>
</head>
<body>
<form id="form1">
<input type="text" name="contact[]" value="" size="8" maxlength="10">
<input type="text" name="contact[]" value="" size="25" maxlength="60">
<input type=button value="Send Form" onclick="xajax_Testing(xajax.getFormValues('form1'));">
</form>
<div id="testDiv"></div>
</body>
</html>

Print_r is returning correct:

<?xml version="1.0" encoding="utf-8" ?>
<xjx>
<cmd cmd="as" id="testDiv" prop="innerHTML">SArray[0]
</cmd><cmd cmd="al"><![CDATA[SArray(    
[contact] => Array        
(            
[0] =>a          
[1] =>b         
)
)
]]></cmd>
</xjx>

But the return I get from $dta[contact][0] is Array[0]

Re: Form problem

Hi,

Never too late...

<?php
require_once ("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
function Testing($dta)
{
$newContent = $dta['contact'][0]; //NOTE: content in quotes...
  $objResponse = new xajaxResponse();
  $objResponse->assign("testDiv","innerHTML", $newContent);
  $objResponse->alert(print_r($dta,true));
  return $objResponse;
}
$xajax->setFlag('debug', true);
$xajax->registerFunction("Testing");  //Register the function
$xajax->processRequest(); //Call the XAJAX engine 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php $xajax->printJavaScript('xajax/'); ?>
</head>
<body>
<form id="form1">
<input type="text" name="contact[]" value="" size="8" maxlength="10"/><br/>
<input type="text" name="contact[]" value="" size="25" maxlength="60"/>
<input type=button value="Send Form" onclick="xajax_Testing(xajax.getFormValues('form1'));"/>
</form>
<div id="testDiv"></div>
</body>
</html>

Ed

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