Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
More extended Glitch form element and logic
<?php
class Application_Model_Form_Html5 extends Zend_Form
{
public function init()
{
$email = new Glitch_Form_Element_Text_Email('email');
$email->setLabel('Email');
$url = new Glitch_Form_Element_Text_Url('url');
$url->setLabel('Url');
$number = new Glitch_Form_Element_Text_Number('number', array(
'min' => 2,
'step' => 2,
'label' => 'Number',
));
$range = new Glitch_Form_Element_Text_Range('range', array(
'min' => 5,
'max' => 100,
'step' => 5,
'autoloadValidators' => false,
'autoloadFilters' => false,
'label' => 'Range',
));
$date = new Glitch_Form_Element_Text_Date('date');
$date->setLabel('Date');
$month = new Glitch_Form_Element_Text_Month('month');
$month->setLabel('Month');
$week = new Glitch_Form_Element_Text_Week('week');
$week->setLabel('Week');
$time = new Glitch_Form_Element_Text_Time('time');
$time->setLabel('Time');
$dateTime = new Glitch_Form_Element_Text_DateTime('datetime');
$dateTime->setLabel('DateTime');
$dateTimeLocal = new Glitch_Form_Element_Text_DateTimeLocal('datetime-local');
$dateTimeLocal->setLabel('DateTimeLocal');
$search = new Glitch_Form_Element_Text_Search('search');
$search->setLabel('Search');
$color = new Glitch_Form_Element_Text_Color('color');
$color->setLabel('Color');
$opts = array(
'foo' => 'bar',
'baz' => 'bat',
);
$datalist = new Glitch_Form_Element_Datalist('datalist');
$datalist->setLabel('Datalist')
->setMultiOptions($opts);
$output = new Glitch_Form_Element_Output('output');
$output->setLabel('Output')->setAttrib('onforminput', 'resCalc()');
$keygen = new Glitch_Form_Element_Keygen('keygen');
$keygen->setAttrib('keytype', 'rsa');
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setValue('submit');
$elements = array($email, $url, $number, $range, $date, $month, $week, $time,
$dateTime, $dateTimeLocal, $search, $color, $output, $datalist, $submit
);
$this->addElements($elements);
}
}
<?php
echo $this->form;
$this->headScript()->captureStart();
?>
function resCalc()
{
numA=document.getElementById("range").value;
numB=document.getElementById("number").value;
document.getElementById("output").value=Number(numA)+Number(numB);
}
<?php
$this->headScript()->captureEnd();
?>
<?php
/**
* Glitch
*
* Copyright (c) 2010, Enrise BV (www.enrise.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Enrise nor the names of his contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Glitch
* @package Glitch_Form
* @subpackage Element
* @author Enrise <info@enrise.com>
* @copyright 2010, Enrise
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id: $
*/
/**
* Base class for HTML5 url element
*
* @category Glitch
* @package Glitch_Form
* @subpackage Element
*/
class Glitch_Form_Element_Text_Url extends Glitch_Form_Element_Text
{
}
<?php
/**
* Glitch
*
* Copyright (c) 2010, Enrise BV (www.enrise.com).
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Enrise nor the names of his contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @category Glitch
* @package Glitch_Form
* @subpackage Element
* @author Enrise <info@enrise.com>
* @copyright 2010, Enrise
* @license http://www.opensource.org/licenses/bsd-license.php
* @version $Id: $
*/
/**
* Base class for HTML5 number element
*
* @category Glitch
* @package Glitch_Form
* @subpackage Element
*/
class Glitch_Form_Element_Text_Week extends Glitch_Form_Element_Text
{
/**
* Initialize additional element options
*
* @return Glitch_Form_Element_Text_Week
*/
public function init()
{
if ($this->isAutoloadValidators())
{
//@todo: base week numbers on Zend_Locale
$this->addValidator('Between', false, array('min' => 1, 'max' => 52));
}
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment