[eluser]Pascal Kriete[/eluser]
I'm not very familiar with the ci library in question. I also very much dislike inline javascript. Here's what I would do (not using the ci library, just general prototype):
Here's the form:
Code:
<form action="path/to/non-ajax/function" id="the_name_form" method="post">
<input type="text" id="my_name" />
<input type="button" id="submit" />
</form>
<div id='ajax_answer'></div>
In the html <head> somewhere:
Code:
<script src="prototype.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
<!--
init = function() {
$('the_name_form').observe('submit', sendIt);
}
sendIt = function(event) {
event.stop();
var url = 'path/to/ajax/function';
new Ajax.Request(url, {
parameters: { name: $F('my_name') },
method: 'post',
onComplete: function(truck) {
$('ajax_answer').update("Form sent!");
}
});
}
document.observe("dom:loaded", init);
//-->
</script>
The advantage here is that the form is still usable (provided you have a backend function to handle it) when javascript is disabled.
Hope that helps.
EDIT: Mwahaha, made the forum display the tags. Just for completeness - in the backend you treat it like a normal form submit, but echo what you want your ajax response to be. You can get that response from truck.responseText (I like using truck - don't ask).