[tipos commit] r1596 - in branches/FreeForm/Tipos/App: . Forms/View

0 views
Skip to first unread message

codesite...@google.com

unread,
Oct 3, 2008, 3:14:22 PM10/3/08
to tipo...@googlegroups.com
Author: rodrigo.moraes
Date: Fri Oct 3 12:10:25 2008
New Revision: 1596

Added:
branches/FreeForm/Tipos/App/Forms/View/fromRecord.php (contents, props
changed)
Modified:
branches/FreeForm/Tipos/App/Forms.php

Log:
Added record-based form examples.
Whitespace changes.

Modified: branches/FreeForm/Tipos/App/Forms.php
==============================================================================
--- branches/FreeForm/Tipos/App/Forms.php (original)
+++ branches/FreeForm/Tipos/App/Forms.php Fri Oct 3 12:10:25 2008
@@ -1,92 +1,98 @@
<?php
/**
- *
+ *
* Demo app for Tipos_View_Helper_FormNew.
- *
+ *
* @category Tipos
- *
+ *
* @package Tipos_App
- *
+ *
* @subpackage Tipos_App_Forms
- *
+ *
* @author Rodrigo Moraes <rodrigo...@gmail.com>
- *
+ *
* @license http://opensource.org/licenses/bsd-license.php BSD
- *
+ *
* @version $Id$
- *
+ *
*/
class Tipos_App_Forms extends Solar_App_Base
{
/**
- *
+ *
* The default controller action.
- *
+ *
* @var string
- *
+ *
*/
protected $_action_default = 'index';
-
+
/**
- *
+ *
* Name of the default layout to be rendered.
- *
+ *
* @var string
- *
+ *
*/
protected $_layout_default = 'forms';
-
+
/**
- *
+ *
* List of Solar_Form instances used in the page.
- *
+ *
* @var array
- *
+ *
*/
public $forms = array();
-
+
/**
- *
+ *
* Executes after construction.
- *
+ *
* @return void
- *
+ *
*/
protected function _setup()
{
+ // register a Solar_Sql object if not already
+ if (! Solar_Registry::exists('sql')) {
+ Solar_Registry::set('sql', Solar::factory('Solar_Sql'));
+ }
+
// Set the layout title.
$this->layout_head['title'] = get_class($this);
-
+
$this->layout_head['meta'][] = array(
'http-equiv' => 'Content-Type',
'content' => 'text/html; charset=utf-8',
);
}
-
+
/**
- *
+ *
* Executes before each action.
- *
+ *
* @return void
- *
+ *
*/
protected function _preAction()
{
}
-
+
/**
- *
+ *
* Main page.
- *
+ *
*/
public function actionIndex()
{
+ // nothing here
}
-
+
/**
- *
+ *
* Simple form for 'subscriptions'.
- *
+ *
*/
public function actionSubscribe()
{
@@ -94,19 +100,19 @@
//
// Form setup.
//
-
+
$form = Solar::factory('Solar_Form');
-
+
$form->setElement('hidden-1', array(
'type' => 'hidden',
'value' => 'some_value',
));
-
+
$form->setElement('hidden-2', array(
'type' => 'hidden',
'value' => 'some_value',
));
-
+
$form->setElement('e-mail', array(
'type' => 'text',
'label' => 'LABEL_EMAIL',
@@ -114,18 +120,18 @@
'require' => true,
'filters' => array('ValidateEmail'),
));
-
+
$this->forms['subscribe'] = $form;
-
+
//
-----------------------------------------------------------------
//
// Form process.
//
-
+
if ($this->_isProcess('subscribe')) {
-
+
$form->populate();
-
+
if ($form->validate()) {
$this->_session->setFlash('subscribed', true);
$this->_redirect('forms/subscribe');
@@ -133,11 +139,64 @@
$form->feedback = $this->locale('FAILURE_SUBSCRIBE');
}
}
-
+
// Was this from a "subscribe" process request?
if ($this->_session->getFlash('subscribed')) {
$form->setStatus(true);
$form->feedback = $this->locale('SUCCESS_SUBSCRIBE');
+ }
+ }
+
+ /**
+ *
+ * Form based on a Solar_Sql_Model_Record
+ *
+ */
+ public function actionFromRecord()
+ {
+ $model = Solar::factory('Tipos_Model_Books');
+ $record = $model->fetchOneByIsbn('0596006810');
+
+ // Insert our example record
+ if (! $record) {
+ $record = $model->fetchNew(array(
+ 'name' => 'Programming PHP',
+ 'author' => 'Rasmus Lerdorf, Kevin Tatroe, Peter
MacIntyre',
+ 'publisher' => 'O\'Reilly Media, Inc',
+ 'isbn' => '0596006810',
+ 'release' => '2006-04-28 00:00:00',
+ 'summary' => 'Programming PHP helps you up the PHP
learning
+ curve, very nearly guaranteeing that you\'ll find in
its
+ pages an example that illustrates every fundamental
aspect
+ of the language and its most important extension
modules.',
+ ));
+ $record->save();
+ }
+
+ $form = $record->form();
+ $this->forms['from-record'] = $form;
+
+ //
-----------------------------------------------------------------
+ //
+ // Form process.
+ //
+
+ if ($this->_isProcess('save')) {
+
+ $form->populate();
+
+ if ($form->validate()) {
+ $this->_session->setFlash('saved', true);
+ $this->_redirect('forms/from-record');
+ } else {
+ $form->feedback = $this->locale('FAILURE_SAVE');
+ }
+ }
+
+ // Was this from a "save" process request?
+ if ($this->_session->getFlash('saved')) {
+ $form->setStatus(true);
+ $form->feedback = $this->locale('SUCCESS_SAVE');
}
}
}

Added: branches/FreeForm/Tipos/App/Forms/View/fromRecord.php
==============================================================================
--- (empty file)
+++ branches/FreeForm/Tipos/App/Forms/View/fromRecord.php Fri Oct 3
12:10:25 2008
@@ -0,0 +1,61 @@
+<?php
+/**
+ *
+ * Subscription form view.
+ *
+ * @category Tipos
+ *
+ * @package Tipos_App
+ *
+ * @subpackage Tipos_App_Forms
+ *
+ * @author Rodrigo Moraes <rodrigo...@gmail.com>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $Id$
+ *
+ */
+?>
+<?php
+ // Set form CSS
+ $this->forms['from-record']->attribs['class'] = 'horiz-rt form-blue';
+
+ // Load the form.
+ $form = $this->freeForm($this->forms['from-record']);
+
+ // Display form header.
+ echo $form->start();
+?>
+ <fieldset>
+ <legend><em><?php echo
$this->getText('LEGEND_BOOK_BASIC'); ?></em></legend>
+ <?php
+ echo $form->auto(array(
+ 'example_books[name]',
+ 'example_books[author]',
+ 'example_books[publisher]',
+ 'example_books[summary]',
+ ));
+ ?>
+ </fieldset>
+ <fieldset class="alt">
+ <legend><em><?php echo
$this->getText('LEGEND_BOOK_TECHNICAL'); ?></em></legend>
+ <?php
+ echo $form->auto(array(
+ 'example_books[isbn]',
+ 'example_books[release]',
+ ));
+ ?>
+ </fieldset>
+
+ <fieldset class="submit">
+ <?php
+ // Display submit buttons.
+ echo $this->freeFormSubmit(array('save', 'cancel'));
+ ?>
+ </fieldset>
+
+<?php
+ // Display form footer.
+ echo $form->stop();
+?>

Reply all
Reply to author
Forward
0 new messages