| @@ -2,25 +2,33 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace BitCode\BitForm\API\BitForm_Public; |
| 4 | 4 | |
| 5 | 5 | use BitCode\BitForm\Core\Database\ApiModel; |
| 6 | +use BitCode\BitForm\Core\Util\Utilities; | |
| 6 | 7 | |
| 7 | -class BitForm_Public { | |
| 8 | - public static function getForms() { | |
| 8 | +class BitForm_Public | |
| 9 | +{ | |
| 10 | + public static function getForms() | |
| 11 | + { | |
| 9 | 12 | $db = new ApiModel(); |
| 10 | 13 | $forms = $db->getForm(); |
| 11 | 14 | return $forms; |
| 12 | 15 | } |
| 13 | 16 | |
| 14 | - public static function getFields($formId) { | |
| 17 | + public static function getFields($formId) | |
| 18 | + { | |
| 15 | 19 | $db = new ApiModel(); |
| 16 | 20 | $formData = $db->getField($formId); |
| 17 | 21 | if (!empty($formData)) { |
| 18 | - $unset_types = ['paypal', 'razorpay', 'stripe', 'recaptcha']; | |
| 19 | - $formContent = json_decode($formData[0]->form_content); | |
| 22 | + $unset_types = ['paypal', 'razorpay', 'stripe', 'recaptcha', 'hcaptcha']; | |
| 23 | + $formRow = Utilities::firstRow($formData); | |
| 24 | + $formContent = Utilities::jsonObj($formRow->form_content ?? ''); | |
| 25 | + if (!$formContent || !isset($formContent->fields)) { | |
| 26 | + return (object) []; | |
| 27 | + } | |
| 20 | 28 | foreach ($formContent->fields as $key => $field) { |
| 21 | 29 | if (in_array($field->typ, $unset_types)) { |
| 22 | - unset($formContent->fields->{$key}, $fieldsKey[$key]); | |
| 30 | + unset($formContent->fields->{$key}); | |
| 23 | 31 | } |
| 24 | 32 | } |
| 25 | 33 | return $formContent->fields; |
| 26 | 34 | } |