|
Step 4: Creating a Form
Form rendering and validation:
<?php
/* Load libraries. */ require_once MOPPLE_BASE . '/lib/base.php'; require_once MOPPLE_BASE . '/lib/MP3Form.php'; require_once 'Horde/Variables.php';
/* Initialize variables. */ $variables = &Variables::getDefaultVariables(); $id = $variables->get('id'); $edit = !empty($id); $title = $edit ? _("Edit MP3") : _("Add MP3");
/* Create form instance. */ $form = &new MP3_Form($variables, $title);
/* Validate form submission. */ if ($form->validate($variables)) { /* The form was submitted and had valid data. */ require_once MOPPLE_BASE . '/lib/Driver.php'; $driver = &Mopple_Driver::singleton($conf['storage']['driver']); $id = $driver->add($variables->get('song_title'), $variables->get('song_artist'), $variables->get('song_album')); if (is_a($id, 'PEAR_Error')) { $notification->push($id, 'horde.error'); } else { $message = $edit ? _("The MP3 \"%s\" has been updated sucessfully.") : _("The MP3 \"%s\" has been added successfully."); $notification->push(sprintf($message, $variables->get('song_title')), 'horde.success'); header('Location: ' . Horde::applicationUrl('list.php', true)); exit; } }
/* Output HTML. */ require MOPPLE_TEMPLATES . '/common-header.inc'; require MOPPLE_TEMPLATES . '/menu.inc'; $renderer = &$form->getRenderer(); $form->renderActive($renderer, $variables, Horde::selfUrl(), 'post'); require $registry->get('templates', 'horde') . '/common-footer.inc';
?>
|