[eluser]iwillsoarlikeaneagle[/eluser]
@LuckyFella73: Sorry for this late reply.
Here's a part of my form_view.php from the views folder:
Code:
<?php echo form_open('Form');?>
Full Name:<br />
<?php
$attrib = array('id' => 'fname',
'name' => 'fname'
);
echo form_input($attrib).form_error('fname');
?>
<br />E-mail Address:<br />
<?php
$attrib = array('id' => 'email',
'name' => 'email'
);
echo form_input($attrib).form_error('email');
?>
<br /><br />
<?php
$attrib = array('id' => 'submit_item',
'name' => 'submit_item',
'value' => 'Add Person'
);
echo form_submit($attrib);
?>
<?php echo form_reset('reset', 'Reset Fields'); ?>
<?php echo form_close(); ?>
..the js found at the header(I've put the js tags and the source for the jquery.js):
Code:
$(document).ready(function()
{
$("#submit_item").click(function ()
{
var item = $('#fname').val();
var item = $('#email').val();
$.post("Form/add_person", { "fname" : item, "email" : item }, // extend the brackets {} with your items seperated with ","
function(data) { // when your callback func. answers here we go
// in this example your callback function returned variable "result"
// in json encoded
alert(data.result);
// return a flag (from callback funct.) when the formdata is saved and everything is fine
// print message here -> depending on the flag ("success" or "try again")
}, 'json');
});
});
..here's the add_person function in my form.php controller:
Code:
function add_person()
{
$this->form_validation->set_rules('fname', ' ', 'trim|required|xss_clean');
$this->form_validation->set_rules('email', ' ', 'trim|required|valid_email');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('form_view');
}
else
{
$this->load->model('Form_model', '', TRUE);
$this->Form_model->add_person();
//
}
}
Help:
1. What's the json_encode function for?
2. I'm confused. With the "starting pt." that you've shared (esp. for the callback function process()), I don't know what to do next with my codes.