[eluser]Lone wolf[/eluser]
anybody tested these code? ->
http://www.alexajax.com/processform
Controller: processform.php
Code:
<?php
class processform extends Controller
{
function processform()
{
parent::Controller();
$this->load->helper(array('text', 'typography'));
}
function index()
{
// XAJAX
$this->load->library('xajax');
$this->xajax->registerFunction(array("process_form_data", &$this, "process_form_data"));
$this->xajax->processRequests();
$data['xajax_js'] = $this->xajax->getJavascript(null, '/js/xajax.js');
// load views
$data['head_title'] = WEBSITE_NAME . " - Examples: Calculator";
$data['highlighted_controller'] = highlight_file("processform.php", TRUE);
// load example MVC
$example = new example('processform', true);
$data['highlighted_view'] = $example->view;
$data['subheader'] = $this->load->view('examples_subheader', $data, true);
$data['sidebar'] = $this->load->view('examples_sidebar', $data, true);
$data['body_content'] = $this->load->view('processform_tpl', $data, true);
$this->load->view('site_layout', $data);
}
function process_form_data($form_data)
{
$objResponse = new xajaxResponse();
$gender = $form_data['rad_gender'][0];
$chk_public = isset($form_data['chk_public'][0]) ? ("Yes") : ("No");
$txt_name = $form_data['txt_name'];
$txt_comments = nl2br_except_pre($form_data['txt_comments']);
$result = "<b>Gender</b>: " . $gender . "<br/><b>Public</b>: " . $chk_public . "<br/><b>Name</b>: " . $txt_name . "<br/><b>Comments</b>: <br/>" . $txt_comments;
$objResponse->addAssign("div_result", "innerHTML", $result);
return $objResponse;
}
}
?>
View: processform_tpl.php
Code:
<!--
xajax.loadingFunction = function(){xajax.$('loading_message').style.display='block';};
xajax.doneLoadingFunction = function(){xajax.$('loading_message').style.display='none';};
// -->
<div id="loading_message" class="loadingMessage">Loading ...</div>
<h1 id="introduction">Process Form</h1>
<p>
This page demonstrates how to process a form with <?=XAJAX_LINK_POPUP?> in <?=CODE_IGNITER_LINK_POPUP?>. You can also refer to the <a href="http://wiki.xajaxproject.org/Tutorials:Processing_Forms_with_xajax" target="_new">tutorial</a> of how to use xajax.getFormValues().
</p>
<form id="form_comments" name="form_comments">
<table>
<tr>
<td valign="top">Gender: </td>
<td>
<input type="radio" id="rad_gender" name="rad_gender[]" value="Male" checked>Male</input>
<input type="radio" id="rad_gender" name="rad_gender[]" value="Female">Female</input>
</td>
</tr>
<tr>
<td valign="top">Public: </td>
<td><input type="checkbox" id="chk_public" name="chk_public[]" value="1">Make this comments public</input></td>
</tr>
<tr>
<td valign="top">Name: </td>
<td><input type="text" id="txt_name" name="txt_name" size="30" maxlength="30" /></td>
</tr>
<tr>
<td valign="top">Comments: </td>
<td><textarea id="txt_comments" name="txt_comments" rows="6" cols="40" maxlength="500"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="button" id="btn_submit" value="Submit" onclick="xajax_process_form_data(decodeURIComponent(xajax.getFormValues('form_comments')));" /></td>
</tr>
</table>
</form>
<br/>
<div id="div_result"><i>Result will be posted here...</i></div>
<h1 id="introduction">Controller: processform.php</h1>
<p>
<?=$highlighted_controller?>
</p>
<h1 id="introduction">View: processform_tpl.php</h1>
<p>
<?=$highlighted_view?>
</p>
i've copied and pasted codes like that, but it's not worked.
if you have perfect codes, plz post them or tell me how to modify the codes at the link about.
I also dont know the meaning of these lines:
Code:
// load example MVC
$example = new example('processform', true);
$data['highlighted_view'] = $example->view;