program/site to generate html form code based on mysql database - php

I have a mysql databased with many tables and fields. I would like to quickly generate a set of prototype forms based on the mysql database (or create table statements). Anyone have any suggestions? html form code would be great. Full PHP validation and insert updates would be even better. Also Zend framework code would be ideal.
I was looking at mySQL workbench which has an excelent reverse engineering and visual presentaion of databases, but no form generator.

You're looking for a thing called scaffolding.
Scaffolding is a meta-programming method of building database-backed software applications. It is a technique supported by some model-view-controller frameworks, in which the programmer may write a specification that describes how the application database may be used. The compiler uses this specification to generate code that the application can use to create, read, update and delete database entries, effectively treating the template as a "scaffold" on which to build a more powerful application.
Please note that ZF and other PHP frameworks are not MVC frameworks - at least those popular like ZF, Symfony, Kohana, CakePHP etc.
It seems that ZF has built-in support for scaffolding: Zend_Controller_Front_Scaffold.

well, what you want is a little too much specific (not saying that it doesn't exist). maybe this could help you with the boring task of writing the html tags:
http://code.google.com/p/zen-coding/

Related

Template engine for single PHP page with structured content?

I'm planning to build a single PHP web page that will contain lots of structured data in nested divs, spans, bootstrap elements etc., like:
Hardware
Notebooks
HP
Apple
Dell
Tablets
Apple
Samsung
Software
Operating Systems
Windows 10
...
The list ist really long with far more than 100 elements. The elements will change from time to time, but the structure will be the same for all elements and sub-elements.
Now, I wonder if plain HTML+CSS is the best way to code this page. As the structure of the elements is always the same, so it would probably be a good idea to use templates. However, I'm not sure if I really should set up a database and some kind of PHP framework like Slim or Laravel/Lumen in order to generate the code. After all, it's just a single page without and routing, forms, login etc. So this might be too much.
Perhaps, a templating engine like Plates could be the answer? But where should I store the data?
What would be your choice for such a use case? Single page with lots of structured data?
Any help is greatly appreciated!
Based on your subject line, I want to clarify something and then suggest a solution.
PHP Components & Composer
State of the art PHP development utilizes Composer to orchestrate component libraries. This could be in the form of a full stack framework or in the form of just a few specific component libraries that solve the problems you have.
Datastores
Your sample shows data with simple hierarchy. Certainly for ease of maintenance a datastore of some type would be helpful. A relational database or a document database will do the job. If that is what you want I'm going to suggest you use a specific ORM or at least a portion of it, and that ORM is Doctrine.
Why Doctrine? Because it supports a number of the most popular open source RDBMS, and it also allows you to use it's DBAL layer without the full ORM, if you just want to implement a few simple queries. With that said, if you have the option of using MongoDB, MongoDB collections support hierarchies very well. A great feature of Doctrine2 is that it has support for MongoDB, which differentiates it from most other PHP ORM's.
The only real reason to go to all this trouble is that you also intend to create an administration tool that will let you maintain your hierarchical data. If you don't, you could just as easily have a script that you include that has the data in PHP array form.
Templating
For templating, my suggestion is that you use Twig. As part of the Symfony components, Twig is both self contained and part of the Symfony full stack framework. It's robust and well designed, and has numerous features (although to be fair, Laravel's Blade has similar features in most cases) and includes support for ESI which could be a great feature for a relatively static page like the one you describe.
Templating in twig, vs writing PHP code to do the same, lets you focus on your markup and avoid introducing a lot of PHP code that will turn your view code into spaghetti.
Components
The important thing is that you can simply use the few components you need to support your application, and you certainly don't need either Laravel or Symfony. Since Symfony began its life as components (and was the foundation for the Laravel project in fact) I'd push you towards the Symfony components, although at the end of the day, you could also utilize parts of Laravel (Blade, Eloquent) in the same way that I'm advocating you use portions of Symfony. Symfony simply is the community and stack I prefer, and has a longer history of being used on a component basis in other projects.
Try out the new minimal Symfony4
Last but not least, the newest version of Symfony (Symfony 4) is really worth looking at for a number of reasons. It essentially is now a micro framework, that comes with the bare minimum of components. They advertise it as 70% smaller than v3.
What differentiates this release is the innovation of Symfony flex with recipes and Composer integration. It is now built to automate a lot of the things that you might otherwise have had to figure out on your own for putting these components together into an application.
Take a look at it and see if it might help you get your application built with minimal components and minimal time spent having to learn how to make things work together.
In summary, I'd suggest you consider:
Symfony Components (You might want a few more depending on your
final solution).
Doctrine2
Twig
Symfony4

Simple CRUD Generation

This is what I have:
An entity-relational schema, modelled for Doctrine 2.0 (in PHP);
The generated database, on a MySQL server.
This is what I want:
A very basic CRUD web-interface to the database, that allows me to (you guessed it!) create, read, update and delete records, with extra credit for implementing CRUD operations on entities and relations instead of records.
Now, I'm terrible at writing web applications myself (read: I'm lazy). Are there any options to generate a CRUD web application from a MySQL database, or from a set of Doctrine entities?
I'd be willing to stop using PHP (and thus rewrite the entities for JPA, Ruby ActiveRecord, etc...) but not MySQL.
I see a lot of similar questions: however, most of these questions have answers that give CRUD operations for in PHP code, or recommend using Doctrine.
An answer such as "There is no such tool, stop being lazy" would also be appreciated.
You should have a look at Grocery CRUD.
Really simple, easy to use /deploy and neat UI.
http://www.web-and-development.com/grocery_crud/
I did a complete web CRUD of my DB in a couple of hours (including additional PHP webservices) Amazing :-)
Symfony does this (at least the 1.x series I am used to). I should think version 2.0 also does, under either Doctrine or Propel (and both of those will work with MySQL).
CakePHP (user guide) takes a database model and generates controllers that do basic CRUD operations for all of your tables. It also includes views and a basic stylesheet.
If your hosting setup can handle Python, the web2py framework offers instant CRUD for a database and a very user friendly (and laziness-friendly) online dev environment. I don't think it's designed to be laid overtop of an existing database, but you can import a CSV file with your database contents. http://www.web2py.com
One of the great things about web2py is that creating custom (public) CRUD pages is also dead easy. In a controller file it's as easy as
form = CRUD.create(db.myTable)
return dict(form = form)
Then in a view file you just add
{{=form}}
And that's it! All of the form creation, input validation, etc., is handled for you. I should also add that the data abstraction layer in web2py is very easy to learn and meshes with mySQL easily. One great thing about it is that web2py performs on-the-fly changes to your datastructure or even migrations from one DB back-end to another.
Not every hosting company knows how to support web2py, but it's easy to deploy on the Google App Engine or with a company like Fluxflex.com
I've been looking for a drop-in admin panel like this too, so far I've 3:
AjaxCrud - http://ajaxcrud.com/
Peek from Code Canyon - http://bit.ly/toKKrB
SQLBuddy - http://www.sqlbuddy.com/
Love to hear any other suggestions!
Ruby on Rails' "Scaffolding" should be exactly what you're looking for...
As according to this answer, I've tried Xataface, which gave me as decent a result as CakePHP or Web2Py would have given me. Am now trying Symfony 2.0 (which is a lot harder then I'd have expected) for the extra credit.

Is there any php framework which exactly reflect the msaccess

I am fond of dbstructure definition of msaccess which lets defining at once and creating the data entry forms, datatables and reports at once easily.
I have been searching for some framework which would generate the data entry forms, data tables and reports easily. I guess the only thing I need to define is complete datatable structure.
Is there any like that or better one than that?
EDIT:
well i am afraid that PHP frameworks have been limited to programmers only. I would like to extend it with some automated functions like autoform in msaccess which would generate data entry form, auto report for data listing. So that my development time would be again some less. I found doctrine nearly matching my specification but not sure as i haven't fully explored doctrine
Cake offers both "hard" (bake) and "soft" scaffolding, which should be very close to what you want. It's still only meant as a quick proof-of-concept tool and to get you up and running faster so you can concentrate on programming the business logic. It's not meant as a hands-off solution nor to be used in production.
What you seem to be looking for is a database frontend like phpMyAdmin or SQL Buddy, not a PHP framework.
Symfony provides an admin generator that builds all the forms on the fly and it will also update itself when you change your db schema. It is based on doctrine which you say you looked at so that would make things a bit easier for you.

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 devs are not so experienced
The DB is being migrated from Access and was not designed with OOP in mind, it's basically a collection of tables divided by functionality, so I probably don't need any ORM (at least for now).
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.
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);
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.
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)
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
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
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;
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.
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.

Shortcuts for creating/modifying web forms in PHP?

I'm new to PHP and before I waste a lot of time doing things the hard way, I wanted to find out if there are shortcuts/techniques to creating PHP web forms apps. All this app will do is display web forms with data from 1 or more tables. In addition to displaying data, the user must be able to update the form and add new data to the forms. I know how to to do all this by manually writing all the PHP/HTML code. But I'm looking for anything that can save me time.
Unfortunately, I can't use any of the fancy PHP libraries such as CakePHP for this. I'm restricted to using the core PHP framework, Oracle for the database and the OCI library for Oracle access.
Given these constraints, what the easiest way to support CRUD operations in a basic PHP forms app? Are there code generators or other tools that can help?
Unfortunately, I can't use any of the fancy PHP libraries such as CakePHP for this. I'm restricted to using the core PHP framework,
Most PHP frameworks are written in PHP. So you wouldn't have to install anything to use them.
That said, forms are rather non-trivial. Treating a form as a separate component only works to some extend. Because of that, many frameworks have forms deeply integrated into them, and not as a standalone component.
You could take a peek at Zend Framework's (now known as Laminas) Form component
. It's fairly self-sufficient and feature-rich.
I build all of my forms on top of a "fillInFormValues($html, $request, $formErrors);" function. See my article at OnLamp for details and full source code.

Categories