Welcome Guest, Not a member yet? Register   Sign In
javascript calling controler without form
#11

[eluser]attos[/eluser]
Hi! A week after and two unaswered questions.

You can serialize the form using jQuery plugins (http://docs.jquery.com/Ajax/serialize or http://malsup.com/jquery/form/). These plugins will send name-value pairs for those elements with a name attribute. Your controller-model should get the values from the input object ($value=$this->input->post("name")) and decide to insert or update a table.

There are no special considerations on handling the data from the form as long as you use CIs methods, except that the data needs to be escaped and filtered. The best way of doing this is by using CI's active record class.

You should avoid the creation of SQL statements by concatenating the data from the user. For example, DO NOT USE SOMETHING LIKE:

Code:
$value = $this->input->post("element_name");
$sql = "INSERT INTO table_name (field_name) VALUES ('$value')";
$query = $this->db->query($sql);

But instead use:

Code:
$value = $this->input->post("element_name");
$params = array("field_name", $value);
$this->db->insert("table_name", $params);
There's a lot of info in CI's documentation. RTM




Theme © iAndrew 2016 - Forum software by © MyBB