Concrete5 5.7 form block type ajax
Permalink
Hi! Please help me.
How to enable ajax for form block type?
For sending form without page reload.
How to enable ajax for form block type?
For sending form without page reload.
This is not an option with the standard form block, you would need to build an external form to do this.
These snippets for a singlepage i'm working on might get you in the right direction.
* For use in a block you probably have to prefix 'action_' before the response function.
controller:
Don't forget the exit.
* For use in a block you probably have to prefix 'action_' before the response function.
function updateCatActive(id, active) { $.ajax({ dataType: "json", type: "post", data: { pk: id, name: 'Active', value: active }, url: "<?php echo $view->action('update_cat_field')?>", success: function(response) { console.log(response); } }); }
controller:
public function update_cat_field() { $ret = array('success' => false, 'message' => t("Error")); if ($this->isPost()) { $catID = $this->post('pk'); $catField = trim($this->post('name')); $catValue = trim($this->post('value')); if (($catID > 0) && is_string($catField) ){ $ret['success'] = true; // do some magic } else $ret['message'] = t('Error' . $catID . $catField . $catValue); } else $ret['message'] = t('Error, no parameters'); echo Core::make('helper/json')->encode($ret); exit; }
Don't forget the exit.