/** * Save the data to the database, but still returns the $for_db array. */ public function save_form() { $for_db = parent::get_encoded_form_array(); $for_db_open311 = parent::open311_form(); $for_db['form_structure_open311'] = $for_db_open311['form_structure']; if ($for_db['form_id']) { $stmt = $this->_db->prepare("UPDATE fb_savedforms SET form_structure = :struct, form_structure_open311 = :struct311 WHERE id = :id"); $stmt->bindParam(':id', $for_db['form_id'], PDO::PARAM_INT); } else { $stmt = $this->_db->prepare("INSERT INTO fb_savedforms (form_structure, form_structure_open311) VALUES (:struct, :struct311)"); } $stmt->bindParam(':struct', $for_db['form_structure'], PDO::PARAM_STR); $stmt->bindParam(':struct311', $for_db['form_structure_open311'], PDO::PARAM_STR); $stmt->execute(); }
<?php require 'Formbuilder/Formbuilder.php'; // At this stage, we want to pass in the POST value // containing the form. In this example we simply // pass POST directly, but DO NOT use POST without // proper security in place. // The get_encoded_form_array() method returns an array that should be // used to store the values in the database. This array // is also what's passed to the class when rendering // or editing the form. $form_data = isset($_POST['frmb']) ? $_POST : false; $form = new Formbuilder($form_data); $for_db = $form->get_encoded_form_array(); $for_db_raw = $form->open311_form(); //------------------------------------------------------------------------------ // OR, you could use our database object with some database connection // information to automatically save everything to the database. // You could do that like so: require 'Formbuilder/Formbuilder_pdo.php'; //$form_data = isset($_POST['frmb']) ? $_POST : false; $form = new Formbuilder_pdo($for_db); $form->connect(); $form->save_form(); //$form->save_form_open311(); //------------------------------------------------------------------------------ // Here's the example output of get_encoded_form_array() print_r($for_db_raw); //Array //( // [form_id] => 1