GithubHelp home page GithubHelp logo

mtymek / reverseform Goto Github PK

View Code? Open in Web Editor NEW

This project forked from silvester/reverseform

0.0 2.0 0.0 120 KB

Rendering ZF2 forms with viewscripts. It can be extended to render with other frameworks then Twitter Bootstrap.

PHP 100.00%

reverseform's Introduction

ReverseForm

This is an early alpha, things do work but may be changed how they work in future.

Uni-Form form demo at: http://reverseform.modo.si/form/test-uniform

Twitter Bootstrap form demo at: http://reverseform.modo.si/form/test-bootstrap

Introduction

ReverseForm is a form rendering module. It creates the renderer objects through a view helper. It also provides an object which extends Zend\Form\Element called ReverseForm\ExtendedElement which will be usefull to create more complicated elements faster.

Goals

  • Support other frameworks for rendering forms like mobile ones.
  • Add an unified way of creating new elements. It should take care of the JS, CSS and configuration part of an element.
  • Elements should honor localization.

Installation with Composer

  1. Add this project in your composer.json:
    "require": {
        "silvester/reverse-form": "dev-master",
    }
  1. Fetch the repository with composer:
$ php composer.phar update
  1. Enable it in your config/application.config.php file:
return array(
    'modules' => array(
        // ...
        'ReverseForm',
    ),
    // ...
);

Form Renderers

Currently I provide 2 types of renderers, but it is simple to create other renderers by extending the ReverseForm\Renderer. Before you start take a look at the /config/module.config.php all of the options are there.

  • ReverseForm\Renderer\Uniform renders the form with extra markup to make it work with Uni-Form.
  • ReverseForm\Renderer\Bootstrap obviously renders Twitter Bootstrap.

Uniform Renderer

    $this->form->setAttribute('action', $this->url('album', array('action' => 'test-form')));
    $formRenderer = $this->formRenderer($form, 'renderer.uniform', 'vertical'); // vertical or horizontal
    $formRenderer->prepare(); // this is how you create it in your viewscript

Get your css from Uni-Form. Check the path to load the files in the module_config.php.

Bootstrap Renderer

    $this->form->setAttribute('action', $this->url('album', array('action' => 'test-form')));
    $formRenderer = $this->formRenderer($form, 'renderer.bootstrap', 'vertical'); // vertical or horizontal
    $formRenderer->prepare(); // this is how you create it in your viewscript

It does not auto load any css or js files in to your view. If you need to load extra files you can do it from the configuration.

Usage

In your view script do:

	<h1>Form Testing</h1>
	<?php
	$form = $this->form;
	$form->setAttribute('action', $this->url('album', array('action' => 'test-form')));
	$formRenderer = $this->formRenderer($form, 'renderer.uniform', 'horizontal');
	$formRenderer->prepare();
	echo $formRenderer->openTag();
	?>
	
	<div class="well">
	    <?php print_r($form->getMessages()); ?>
	</div>
	
	<fieldset class="<?= $formRenderer->_formStyle; ?>">
	
	<legend>Some Legend</legend>
	
	<?= $formRenderer->formHidden($form->get('security')); ?>
	<?= $formRenderer->formRow($form->get('status')); ?>
	<?= $formRenderer->formRow($form->get('status2')); ?>
	<?= $formRenderer->formRow($form->get('status3')); ?>
	
	<?= $formRenderer->formRow($form->get('codemirrortest')); ?>
	<?= $formRenderer->formRow($form->get('tinymcetest')); ?>
	
	<?= $formRenderer->formRow($form->get('datepicker')); ?>
	<?= $formRenderer->formRow($form->get('datetimepicker')); ?>
	<?= $formRenderer->formRow($form->get('daterangepicker')); ?>
	<?= $formRenderer->formCaptcha($form->get('captchaImage')); ?>
	
	<?= $formRenderer->formRow($form->get('gmap')); ?>
	<?= $formRenderer->formRow($form->get('artist')); ?>
	<?= $formRenderer->formRow($form->get('title')); ?>
	<?= $formRenderer->formRow($form->get('file')); ?>
	
	<?= $formRenderer->formRow($form->get('countrytextarea')); ?>
	<?= $formRenderer->formAction($form->get('actions')); ?>
	</fieldset>
	
	<?= $formRenderer->closeTag(); ?>
	
	<script>$(document).ready(function(){<?= $formRenderer->getElementJsContent(); ?>});</script>

In your action do:

    $form = new ReverseForm\Form\TestForm();

    if ($this->getRequest()->isPost()) {

        $form->setInputFilter(new InputFilter);

        $form->setData($this->getRequest()->getPost());

    }

    return array('form' => $form, 'post' => $this->getRequest()->getPost());

You would do it better

Feel free to improve it. Will merge them in to the project and thank you.

TODO

  • Many element view scripts look the same, only difference is the js part. Refactor all same looking elements in to one viewscript. COMPLETED.
  • Write some decent documentation.
  • Demo module is on it's way.
  • Figure out fieldset templates current way is too ugly

reverseform's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.