Welcome Guest, Not a member yet? Register   Sign In
SOLVED..Xajax not saving form data to file
#1

[eluser]spheroid[/eluser]
When I try to output a form's data to a file, the file saved is simply a "[" (one character). Can't figure this one out. So far I have the following:

Controller

Code:
function xajax()
{
    $this->load->library('xajax');
    $this->xajax->registerFunction(array("process_form_data", &$this, "process_form_data"));
    $this->xajax->processRequest();
    $data['xajax_js'] = $this->xajax->getJavascript(base_url());
}

function process_form_data($form_data)
{
    $objResponse = new xajaxResponse();
    $kmloutput = $form_data['kmloutput'];
    $this->_save_territory_boundaries_xml($kmloutput);
    $objResponse->assign("SomeElementId", "innerHTML", $kmloutput);
    return $objResponse;
}

function _save_territory_boundaries_xml($xmldata)
{
  $File = "/path/to/my/file/test.xml";
  $Handle = fopen($File, 'w+');
  $Data = $this->_parseToXML($xmldata);
  fwrite($Handle, $Data);
  fclose($Handle);
}
    
function _parseToXML($htmlStr)
{
    $xmlStr = str_replace('&', '&', $htmlStr);
        
    return $xmlStr;
}

View

Code:
[removed]
function do_submit()
{
    if (xajax.$('kmloutput').value == '')
    {
        alert("Use the territory button to draw new territory!");
    }
    else
    {
        xajax_process_form_data(decodeURIComponent(xajax.getFormValues('form_feedback')));
        xajax.$('kmloutput').value = '';
    }
}
[removed]

<form id="form_feedback" name="form_feedback">
  &lt;textarea id="kmloutput" name="kmloutput" cols="125" rows="10"&gt;&lt;/textarea><br />
  &lt;input type="button" id="btn_submit" value="Submit" onclick="do_submit()" />
&lt;/form&gt;

<div id="SomeElementId" name="SomeElementId"></div>

Note, the post is removing the start and end Javascript tags (where it says "[removed]").
#2

[eluser]spheroid[/eluser]
Solved...had to change this one line:

Code:
xajax_process_form_data(xajax.getFormValues('form_feedback'));

Hope this helps someone.




Theme © iAndrew 2016 - Forum software by © MyBB