/** * initialise the form row * * @return void * @author Andy Bennett */ function init() { $nm = (string) $this->p->row->name; $c = $this->form->return_form_data('current'); $e = $this->form->return_form_data('existing'); $this->p->current = isset($c->{$nm}) ? $c->{$nm} : false; $this->p->existing = isset($e->{$nm}) ? $e->{$nm} : false; // define the row name $this->p->oname = (string) $this->p->row->name; $this->p->name = 'form_' . $this->p->row->name; // evaluate the method for the row $v = steamform_helper::evaluate_method($this->p->row); if (is_numeric($v) || is_string($v)) { $this->p->row->value = $v; } $r = $this->form->return_form_data('replacements'); $this->p->title = $this->set_title($r); $this->p->row->class = isset($this->p->row->class) ? ' ' . $this->p->row->class : ''; $this->p->row->divclass = isset($this->p->row->divclass) ? ' ' . $this->p->row->divclass : ''; }
/** * set up the form; do replacements, set up validation * * @return void * @author Andy Bennett */ public function setup_form() { // set up an empty array to hold the row objects $this->rows = array(); if (isset($this->form->append_data)) { foreach ($this->form->append_data as $n) { foreach ($n as $k => $v) { Display::instance()->append_data($k, $v); } } } if (!isset($this->form->steamform_js) or $this->form->steamform_js == 'true') { // Display::instance()->add_javascript('/cache/js/steamform'); Display::instance()->add_javascript('/steamform/index/steamform'); } /* <events> <event> <clear>true</clear> <event>steamform_home_stories_edit.complete</event> <class>adminform_helpers</class> <method>event_home_stories_edit_complete</method> </event> </events> */ if (isset($this->form->events)) { foreach ($this->form->events->event as $e) { if (!isset($e->class) or !isset($e->method) or !isset($e->event)) { continue; } $c = (string) $e->class; $m = (string) $e->method; $ev = (string) $e->event; if (isset($e->clear) and (string) $e->clear == 'true') { Event::clear($ev); } Event::add($ev, array($c, $m)); } } // iterate through the form pages foreach ($this->form->pages->page as $page) { // set a temporary array to hold the row objects $temp_row = array(); $n_row = 0; // iterate through the page rows foreach ($page->rows->row as $row) { // get the name of the row, and the post name $name = (string) $row->name; $fname = 'form_' . $name; // fix any dates steamform_helper::fix_dates($this->post, $row, $fname); // create an instance of the form row object $temp_row[] = new SteamFormRow($this, $row, $n_row); if ($row->type == 'colour') { Display::instance()->append_data('jsfiles', '/cache/js/colour_picker'); } if (isset($row->rules)) { foreach ($row->rules->rule as $rule) { $this->post->add_rules($fname, (string) $rule); } } if (isset($row->filters)) { foreach ($row->filters->filter as $filter) { $this->post->pre_filter((string) $filter, $fname); } } if (isset($row->callbacks)) { foreach ($row->callbacks->callback as $callback) { $this->post->add_callbacks($fname, array((string) $callback['class'], (string) $callback)); } } $n_row++; } $this->rows[] = $temp_row; } }
</name> <rules> <rule name="required" error="This field is required">required</rule> </rules> <filters> <filter>trim</filter> </filters> <field><?php echo ucwords(str_replace('_', ' ', $field->Field)); ?> </field> <type><?php echo steamform_helper::get_field_type($field); ?> </type> <?php echo steamform_helper::get_field_params($field); ?> </row> <?php } ?> <row submit='0'> <name>submit</name> <field>Submit</field> <type>submit</type> </row> </rows> </page> </pages> </form>
<?php $startyear = isset($o->rp('row')->startyear) ? $o->rp('row')->startyear : false; $dates = steamform_helper::create_dates((int) $startyear); $cval = $o->rp('cval'); echo form::dropdown($o->rp('name') . '_day', $dates['days'], date("d", strtotime($cval))); echo form::dropdown($o->rp('name') . '_month', $dates['months'], date("m", strtotime($cval))); echo form::dropdown($o->rp('name') . '_year', $dates['years'], date("Y", strtotime($cval))); echo $o->get_error($o->rp('name'));
<?php $dates = steamform_helper::create_dates(1930); $cval = $o->rp('cval'); echo form::dropdown($o->rp('name') . '_day', $dates['days'], date("d", strtotime($cval))); echo form::dropdown($o->rp('name') . '_month', $dates['months'], date("m", strtotime($cval))); echo form::dropdown($o->rp('name') . '_year', $dates['dobyears'], date("Y", strtotime($cval))); echo $o->get_error($o->rp('name'));
/** * show the user their profile for editing * * @return void * @author Andy Bennett */ public function profile() { if (!$this->model->test_logged_in()) { throw new Exception('invalid user'); } $id = $this->model->get_user_data()->id; $setup = steamcore::array_object(array('update' => $id, 'form_name' => 'auth_profile', 'model' => $this->model)); // try running the form, throw exception on error (shouldn't happen) try { steamform_helper::run_form($setup); } catch (Exception $e) { throw new Kohana_User_Exception('SteamCore Edit Error', $e->getMessage()); } }
<?php if ($select = steamform_helper::evaluate_method($o->rp('row'))) { $class = $o->rp('row')->class != '' ? $o->rp('row')->class : ''; $class .= ' multiselect'; $cval = $o->rp('cval'); if ($cval != '') { $cval = unserialize($cval); } $e = $o->rp('existing'); if ($e && $e != '') { $e = implode(',', array_keys(unserialize($e))); } ?> <div class="<?php echo $class; ?> "> <?php foreach ($select as $option) { ?> <?php echo form::radio(array('id' => $o->form->get_form_name() . '-' . $o->rp('name') . '_' . $option->id, 'name' => $o->rp('name'), 'checked' => isset($cval[(string) $option->id]), 'value' => $option->id)); ?> <label for="<?php echo $o->rp('name') . '_' . $option->id; ?> "><?php echo $option->title; ?> </label><br/>
/** * build and run an XML form * * @param object $setup * @return void * @author Andy Bennett */ public static function run_form($setup = false) { try { $setup = SteamForm::normalise_setup($setup); $form = SteamForm::factory($setup); // does the form data validate $form->test_form(); // get the data submitted from the form $fc = steamcore::array_object(array('form' => $form->return_form())); // run the validated event Event::run('steamform_' . $setup->form_name . '.validated', $fc); if ($setup->exit_point === 'validated') { return; } // do the uploading foreach ($_FILES as $file => $file_data) { if ($file_data['error'] > 0) { unset($_POST[$file]); } else { // insert the upload into the uploads database $_POST[$file] = $setup->model->insert_upload(upload::get_upload_data($file, $file_data)); } } // run the uploaded event Event::run('steamform_' . $setup->form_name . '.uploaded', $fc); if ($setup->exit_point === 'uploaded') { return; } // if this is an update, get the current values, and pass them into the form if ($setup->update !== false) { $id = isset($setup->id) ? $setup->id : Kohana::instance()->input->post('form_id'); if (!$id || !preg_match('/^[0-9]+$/', $id)) { throw new Exception("No ID supplied"); } $fc->id = $id; // prepare the data for inserting $setup->model->prep_update_formdata($fc); Event::run('steamform_' . $setup->form_name . '.update_prepped', $fc); if ($setup->exit_point === 'prepped') { return $fc; } if ($setup->db) { // insert the data into the database $r = $setup->model->update_formdata($fc); // run the updated event Event::run('steamform_' . $setup->form_name . '.updated', $r); } } else { // prepare the data for inserting $setup->model->prep_insert_formdata($fc); Event::run('steamform_' . $setup->form_name . '.insert_prepped', $fc); if ($setup->exit_point === 'prepped') { return $fc; } if ($setup->db) { // insert the data into the database $r = $setup->model->insert_formdata($fc); // run the inserted event Event::run('steamform_' . $setup->form_name . '.inserted', $r); } } if ($setup->exit_point === 'inserted') { return; } if ($setup->exit_point === 'updated') { return; } // if there is a notify item in the form, run the notify event if (isset($fc->form->notify)) { Event::run('steamform.notify', steamcore::array_object(array('data' => $fc, 'notify' => $fc->form->notify))); } Event::run('audit.cache', steamcore::array_object(array('action' => $setup->update ? 'edit' : 'add', 'id' => $r, 'data' => $fc->data))); // run the inserted event Event::run('steamform_' . $setup->form_name . '.complete', steamcore::array_object(array('id' => $r, 'data' => $fc->data))); } catch (Exception $e) { // if this is an update, get the current values, and pass them into the form if ($setup->update !== false) { $current = steamform_helper::return_current_values($setup->model, $setup->update, $form); $form->set_form_data('current', $current); } if ($e->getCode() != -1) { Kohana::log('error', $e->getMessage()); $form->set_form_data('error', $e->getMessage()); } // generate the html and throw it $f = $form->render(); // run the show_form event Event::run('steamform_' . $setup->form_name . '.show_form', $f); } }
/** * add * * @param object $setup * @return void * @author Andy Bennett */ public function add($setup = false) { // check if user has permission to edit $data = array('action' => 'add', 'name' => $this->name, 'role' => Steamauth::instance()->get_role()); Event::run('steamcore.aclcheck', $data); // set up the defaults $d = array('model' => $this->model, 'form_name' => $this->setup['name'] . '_add', 'form_data' => array()); $setup = steamcore::array_object($d, $setup); // try running the form, throw exception on error (shouldn't happen) try { steamform_helper::run_form($setup); } catch (Exception $e) { throw new Kohana_User_Exception('SteamCore Add Error', $e->getMessage()); } }