Welcome Guest, Not a member yet? Register   Sign In
help with xjax and codeigniter
#1

[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;
    }
}
?&gt;
View: processform_tpl.php
Code:
&lt;!--
    xajax.loadingFunction = function(){xajax.$('loading_message').style.display='block';};
    xajax.doneLoadingFunction = function(){xajax.$('loading_message').style.display='none';};
// --&gt;

<div id="loading_message" class="loadingMessage">Loading ...</div>
<h1 id="introduction">Process Form</h1>

<p>
This page demonstrates how to process a form with &lt;?=XAJAX_LINK_POPUP?&gt; in &lt;?=CODE_IGNITER_LINK_POPUP?&gt;. 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>

&lt;form id="form_comments" name="form_comments"&gt;
<table>
<tr>
    <td valign="top">Gender: </td>
    <td>
        &lt;input type="radio" id="rad_gender" name="rad_gender[]" value="Male" checked&gt;Male&lt;/input&gt;
        &lt;input type="radio" id="rad_gender" name="rad_gender[]" value="Female"&gt;Female&lt;/input&gt;
    </td>
</tr>
<tr>
    <td valign="top">Public: </td>
    <td>&lt;input type="checkbox" id="chk_public" name="chk_public[]" value="1"&gt;Make this comments public&lt;/input&gt;</td>
</tr>
<tr>
    <td valign="top">Name: </td>
    <td>&lt;input type="text" id="txt_name" name="txt_name" size="30" maxlength="30" /&gt;</td>
</tr>
<tr>
    <td valign="top">Comments: </td>
    <td>&lt;textarea id="txt_comments" name="txt_comments" rows="6" cols="40" maxlength="500"&gt;&lt;/textarea&gt;</td>
</tr>
<tr>
    <td>&nbsp;</td>
    <td>&lt;input type="button" id="btn_submit" value="Submit" onclick="xajax_process_form_data(decodeURIComponent(xajax.getFormValues('form_comments')));" /&gt;</td>
</tr>
</table>
&lt;/form&gt;
<br/>

<div id="div_result"><i>Result will be posted here...</i></div>

<h1 id="introduction">Controller: processform.php</h1>
<p>
&lt;?=$highlighted_controller?&gt;
</p>

<h1 id="introduction">View: processform_tpl.php</h1>
<p>
&lt;?=$highlighted_view?&gt;
</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;
#2

[eluser]Unknown[/eluser]
If you use xajax 0.5, replace
$objResponse->addAssign
to
$objResponse->Assign




Theme © iAndrew 2016 - Forum software by © MyBB