Mobile app version of vmapp.org
Login or Join
Ravi8258870

: Form development optimization Like many web developers I do forms all the time. I found myself doing the same all the time: placing input fields, assigning a name to each, ajax the form, then

@Ravi8258870

Posted in: #Automation #Forms #Optimization

Like many web developers I do forms all the time. I found myself doing the same all the time: placing input fields, assigning a name to each, ajax the form, then create the PHP which involves to assign a PHP var to each $_REQUEST['var'], escape and validate data, build the html and emailing the results.

So I found that 70% of the work is duplicated but I just can't duplicate a page and change the fields. I end up wasting more time reformatting, deleting and adding different fields than creating from scratch.

I started planing to program a "list of IDs to html+php" converter in which I'd input all the IDs and this would output the basic html and php. Then I thought: there's got to be thousands of developers that go through this, I'd be reinventing the wheel. So this is my question, I'm trying to find that wheel that somebody must have invented already.

I found this: www.trirand.com/blog/jqform/ which does more or less what I'm looking for but it's an expensive solution and it has too much functionality for what I'd be using it.

Which tools do you use to optimize repetitive task about HTML and PHP?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Ravi8258870

2 Comments

Sorted by latest first Latest Oldest Best

 

@Sims2060225

It's not so much about finding tools to help you generate repetitive PHP/HTML as about designing your app to avoid repetitive code in the first place (whether you have to write it by hand or generate it with something else).

Usually this is done by using a UI library or framework. For instance, in CakePHP, there is the FormHelper and built-in functionality in view, controller, and models to handle forms automagically.

So the developer doesn't need to create the HTML for the form or even the PHP to validate and process the form. All you have to do is define your models (what fields, the types, and the validation rules to use) and then use the form helper to output the form like so:

echo $this->Form->create();
echo $this->Form->input('field1'); // Note: these are the fieldnames from the
echo $this->Form->input('field2'); // model, not the input name or ID, which
echo $this->Form->input('field3'); // will be generated as ModelField and
echo $this->Form->input('field1'); // data[Modelname][fieldname], respectively
echo $this->Form->end('Submit Me!');


Then in your controller, you can save your form data with a single line of code, without having to worry about what fields or validation rules this form has.

To add AJAX functionality, you can then use AJAX helpers for specific AJAX libraries to progressively enhance your forms. However, this too should be accomplished with a few short lines of code, and ought not require that you pass input names or IDs. Ideally, you should be able to do something like this:

$('form').ajaxify();


And it would ajaxify all forms. And this line of code could be included in an external JS file that's used by all form pages to initialize the AJAX UI, instead of each page having field-specific client-side validation or AJAX code.

10% popularity Vote Up Vote Down


 

@Lee4591628

A solution that addresses part of your problem is using PEAR::QuickForm.

With it, you can build quick and easy a form, just by using a simply OOP syntax. You can look at its Tutorial to see how it works.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme