Miguel Ping
Miguel Ping

Reputation: 18347

PHP Framework for form-intensive application

I'm looking for a simple-to-learn php framework for an application that is being migrated from Access to PHP. The application has lots of forms (sometimes 50+ fields per page), and lots of the fields are inter-dependent (ie, you change one field, it updates some other fields or options).

Is there any good php framework for this? I would prefer it really simple since:

The most important thing is really the ease of form design and fields correlation (ex: two list boxes where the values of the second depends of the selected value of the first) - I know most ajax libs have some support for this but I would like it out of the box.


edit: As a clarification, the most important is not the ajax nifty stuff, although it is important. The important is a straightforward way to create db-based forms. The db is not designed with an ORM in mind, so I don't need fancy table associations on the ORM layer whith cascade deletes etc. If an ORM layer doesn't get in the way and simplifies the implementation so that's ok but i doubt this will ever be true.

Upvotes: 8

Views: 13731

Answers (8)

Jon Winstanley
Jon Winstanley

Reputation: 23311

Code Igniter has some very good documentation regarding forms and handles a lot of the complexities for you.

The form validation class is documented here: http://codeigniter.com/user_guide/libraries/form_validation.html

There is also a form helper class which makes creating forms very easy.

http://codeigniter.com/user_guide/helpers/form_helper.html

It is certainly easier than building a web app from scratch!


(source: codeigniter.com)

Upvotes: 5

romaninsh
romaninsh

Reputation: 10664

Leaving general-purpose frameworks aside, for the UI-centric application I recommend ATK UI. It is relatively new (released in 2017) under MIT license. Here is why it's good choice for OP:

  • Designed for those who don't understand HTML / CSS.
  • Creating a form takes just few lines of PHP code.
  • Works with Database or without (up to you).
  • Handles wide range of types, even file uploads through extension.
  • Integrated with SemanticUI, fully responsive.

Installation: there is downloadable ZIP at www.agiletoolkit.org or through composer require atk4/ui.

Syntax:

 <?php

 $app = new \atk4\ui\App();
 $app->initLayout('Centered');
 $form = $app->add('Form');

 $form->addField('name');
 $form->addField('date', null, ['type'=>'date']);

 $form->onSubmit(function($form){ 
    return 'Hello, '.$name;
});

Nothing else is required, to need to install anything or copy assets, it just works. If you like, there are integrations with WP, Laravel and some other full-stack frameworks.

Upvotes: 0

forsberg
forsberg

Reputation: 1913

Wow, this question is so outdated! Anyway, I also consider Symfony (SF) to be the best general purpose framework for PHP, however in SF 2.0+ forms are really complex (hence, complicated), and I don't consider Symfony to be a good option for form-intensive app, unless its requirements are quite specific. It's important to realize what you need: if it's the re-use of code (forms in this case), SF is really good, and their approach is very similar to the one took in the Java EE projects. But if you want results fast, I would look elsewhere, perhaps to Javascript frameworks.

If you want to work with JavaScript directly, look maybe at the jQuery Form Framework project.

Upvotes: 0

Steerpike
Steerpike

Reputation: 17554

While I'll certainly add my support behind the excellent and simple to learn CodeIgniter I fear everyone so far is missing the elephant in the room regarding this question.

To be perfectly honest I don't think any framework is going to make assembling an application with 50+ forms per page simpler or easy for Developers without much experience. Especially with the added requirement of ajax ready support for dropdown dependencies.

Having said that, if you're looking for power and flexibilty I'd select Zend. If you're looking for straight simplicity I'd choose CodeIgniter.

Upvotes: 6

Stefan Gabos
Stefan Gabos

Reputation: 1471

the best is, without a doubt, Zebra_Form, a jQuery augmented PHP library for creating and validating HTML forms: provides both server-side and client-side validation (client-side validation is done using jQuery 1.5.2+) and has a lot of predefined rules that can be used out of the box; custom validation rules (including AJAX-based) can easily be added; has integrated cross-site scripting (XSS) prevention mechanism that automatically strips out potentially malicious code from the submitted data, and also features protection against cross-site request forgery (CSRF) attacks; it prevents automated SPAM posts, out of the box and without relying on CAPTCHAs by using honeypots; forms' layout can be generated either automatically or manually using templates; it's easy to learn, mature, and it is constantly improved;

Upvotes: 2

Peter D
Peter D

Reputation: 4931

I'm a big symfony fan and it has pretty good support for forms with its form helpers. Check out the docs for forms:

http://www.symfony-project.org/book/1_2/10-Forms

Upvotes: 3

jsims281
jsims281

Reputation: 2206

I've just done a similar but much more simple application using codeIgniter, which has a pretty nice form helper

Examples of code:

form_hidden('userName', 'johndoe');
// Would produce: <input type="hidden" name="username" value="johndoe" />

form_input('username', @$_POST['userName'])
// Would produce an input populated with a variable  from the post array

And you can do allsorts using arrays etc:

$js = 'id="shirts" onChange="some_function();"';

echo form_dropdown('shirts', $options, 'large', $js);

Upvotes: 7

karim79
karim79

Reputation: 342655

Have a look at Zend Framework, in particular, Zend_Form.

It is enterprise ready, has excellent beginner to advanced tutorials as well as 'official' training courses, and it's free.

You also might want to check out CodeIgniter

Upvotes: 2

Related Questions