1: <?php
2:
3: 4: 5:
6: class Quform_Form_List_Settings
7: {
8: 9: 10:
11: public function save()
12: {
13: $this->validateSaveRequest();
14: $this->handleSaveRequest();
15: }
16:
17: 18: 19:
20: protected function validateSaveRequest()
21: {
22: if ( ! Quform::isPostRequest() || ! isset($_POST['per_page']) || ! is_string($_POST['per_page'])) {
23: wp_send_json(array(
24: 'type' => 'error',
25: 'message' => __('Bad request', 'quform')
26: ));
27: }
28:
29: if ( ! check_ajax_referer('quform_save_forms_table_settings', false, false)) {
30: wp_send_json(array(
31: 'type' => 'error',
32: 'message' => __('Nonce check failed', 'quform')
33: ));
34: }
35: }
36:
37: 38: 39:
40: protected function handleSaveRequest()
41: {
42: if ( $_POST['per_page'] === '') {
43: wp_send_json(array(
44: 'type' => 'error',
45: 'errors' => array('qfb_forms_per_page' => __('This field is required', 'quform'))
46: ));
47: }
48:
49: if ( ! is_numeric($_POST['per_page'])) {
50: wp_send_json(array(
51: 'type' => 'error',
52: 'errors' => array('qfb_forms_per_page' => __('Value must be numeric', 'quform'))
53: ));
54: }
55:
56: $perPage = (int) $_POST['per_page'];
57:
58: if ($perPage < 1) {
59: wp_send_json(array(
60: 'type' => 'error',
61: 'errors' => array('qfb_forms_per_page' => __('Value must be greater than 1', 'quform'))
62: ));
63: }
64:
65: if ($perPage > 1000000) {
66: wp_send_json(array(
67: 'type' => 'error',
68: 'errors' => array('qfb_forms_per_page' => __('Value must be less than 1000000', 'quform'))
69: ));
70: }
71:
72: update_user_meta(get_current_user_id(), 'quform_forms_per_page', $perPage);
73:
74: wp_send_json(array(
75: 'type' => 'success'
76: ));
77: }
78: }
79: