Ajax actions Ajax actions for form elements (added in v 4.3)

You can now directly perform ajax actions on form elements. For example, on change of textbox/dropdown, if you want to get the some data from database(or any other action) based on value of textbox/dropdown and put it in some textbox/dropdown, you can easily do this using the setAjaxAction function. By default, element on which you apply ajax, it's value will be passed directly. You need to define the function to be called using ajax in script/pdocrud.php and return the required output(if any). You can also define which other element values to be passed along with main element if required. Currently, it works with the textbox/dropdown only and there are some limitation on return value.

In the below example, we are calling the ajax function on change of the exam category id select box. We are also passing the value of student id just to explain how to pass other element's value. The ajax function getAmount is defined in the script/pdocrud.php. You can use the print_r to understand the content of the $data there.

Please note that this feature currently has some limitations as mentioned above and in future version, we will improve as per the requirement/feedbacks.

                                $pdocrud = new PDOCrud();
                                $pdocrud->fieldTypes("student_id", "select");
                                $pdocrud->fieldDataBinding("student_id", "student", "student_id", "first_name", "db");
                                 * Set/Call ajax actions for the form elements on some js event
                                 * @param   string   $elementName                 Name of table column (element name) you want to apply event
                                 * @param   string   $event                       Javascript event name
                                 * @param   string   $callbackFunc                Function to be called upon
                                 * @param   string   $returnValueElement          On which element, return value should be displayed
                                 * @param   string   $otherElements               Other elements to be passed along if any
                                 * return   object                                Object of class
                                $pdocrud->setAjaxActions("expense_category_id","change","getAmount","amount", array("student_id") );
                                 echo $pdocrud->dbTable("payment")->render("insertform"); // call render function