Topic: how to access form values

I'm very new to xajax and found this forum very helpful to far. However, I can't seem to get any data from a form.

I dumbed both code and smary template down to a bare minimum and all I could get from alert(print_r($_POST,true));
is an array:
Array
(
    [xjxfun] => processdata
    [xjxr] => 1258982310134
)

code:
<?php
include('./smartystuff.php');
$smarty->force_compile=1;
$smarty->caching=0;

function processdata($data)
{
    $objResponse=new xajaxResponse();
    $objResponse->alert(print_r($_POST,true));
    return $objResponse;
}

require_once("xajax/xajax_core/xajax.inc.php");
$xajax = new xajax();
$xajax->configure('javascript URI', 'xajax/');
$xajax->register(XAJAX_FUNCTION, "processdata");
$smarty->assign("xajax_javascript", $xajax->getJavascript());

$xajax->processRequest();
$xajax->configure('debug', true);

$smarty->display('test.tpl.php');
?>

test.tpl.php
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home Page</title>
{$xajax_javascript}
</head>
<body>

<h2>Data:</h2>
<form name="company_data" id="company_data" method="POST" onsubmit="xajax_processdata(xajax.getFormValues('company_data'); return false;">
Companyname: <input type="text" class="text" id="companyname" name="companyname" value=""><br/>
<input type="button" name="submit" value="verstuur" class="button" onclick="xajax_processdata();">
</form>
</body>
</html>

Versions:
Smarty 2.6.26
PHP 5.2.1
Xajax 0.5

Any help would be greatly appriciated as I'm quite sure I'm overlooking the obvious here.

Re: how to access form values

Hi,

Try:

Code: PHP

<input type="button" name="submit" value="verstuur" class="button" onclick="xajax_processdata(xajax.getFormValues('company_data));">

 

The form values will be in the $data parameter to the processdata function.

Do not try to use $_POST...

Ed

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

Re: how to access form values

It does work now. I left the onsubmit="return false;" and moved the rest to the onclick like you suggested.

I know about not using $_POST but noticed it was one of the recommendations when debugging.

Thanks much.

Re: how to access form values

Try this

Code: PHP

$objResponse->alert(print_r($data,true));

and this as sugegsted

Code: PHP

<input type="button" name="submit" value="verstuur" class="button" onclick="xajax_processdata(xajax.getFormValues('company_data'));">

Last edited by Sergey Romanov (2010-04-26 9:08:27 AM)