/** * Create tesitmonial form. Called when using the shortcode */ public static function createItemForm($id) { if (!empty($_GET)) { //This is to be removed and put into the model global $wpdb; foreach ($_GET as $key => $value) { if ($key != 'form-id') { $res = $wpdb->get_results("\n SELECT id FROM wp_testimonials_forms_fields\n WHERE form_id = " . $_GET['form-id'] . "\n AND name = '" . $key . "'\n "); $pivot_id = $res[0]->id; $wpdb->insert($wpdb->prefix . "testimonials_values", array('created' => current_time('mysql'), 'pivot_id' => $pivot_id, 'value' => $value)); } } } $formModel = new \Testimonials\Models\FormModel(); $form = $formModel->getItemById($id); include ABSPATH . 'wp-content/plugins/wordpress-testimonials/partials/testimonial_form.php'; }
public static function createNewForm() { $fieldModel = new \Testimonials\Models\FieldModel(); $fields = $fieldModel->getItems(); if (isset($_POST['form-name'])) { $name = $_POST['form-name']; $formModel = new \Testimonials\Models\FormModel(); //Get the added form's id in the database so it can be used for the fields $newFormId = $formModel->addItem($name); $data = null; $data->form_id = $newFormId; for ($i = 0; $i < count($_POST['field-name']); $i++) { //Fill in data to be added to the database $data->field_id = $_POST['field-type'][$i]; $data->name = $_POST['field-name'][$i]; $data->placeholder = $_POST['field-placeholder'][$i]; $fieldModel->addItem($data); } } include ABSPATH . 'wp-content/plugins/wordpress-testimonials/views/create_form.php'; }