WebCM Posted April 12, 2008 Share Posted April 12, 2008 I need a solution for CMS. I would like to edit and create FORMS easily, especially list of settings. Which is better and why? XML or HTML Forms occur in View layer - in presentation file. To simplify editing forms and to improve readability, webmasters use additional tags and attributes, e.g. <checkbox>, <radio>, arrayname... The compiler of templates changes XML code into (X)HTML with conditional expressions in PHP and variables (until the template class doesn't compile templates but parse them). PHP Form fields and their properties are defined in PHP logic code. Form class generates the HTML form. However, the class needs HTML code of each <form> element - perhaps from template Examples: http://code.bulix.org/so4zlh-66117 Example of unclear code: <input type="checkbox" name="name"<!-- IF name --> checked="checked"<!-- END --> /> A lot of such constructions make the code unclear. Similar in pure PHP: <input type="checkbox" name="name" <?= $name ? 'checked="checked"' : '' ?> /> So I'm looking for a good solution for making <form>s. There are 2 or more methods - XML-based or PHP-based. Which is better and why? XML-based - example of checkbox: <checkbox name="name" /> PHP-based: $form = new Form('...'); $form -> set( /*fields, etc. */); $template -> set('form', $form); Quote Link to comment https://forums.phpfreaks.com/topic/100759-generating-forms-xml-or-php/ Share on other sites More sharing options...
keeB Posted April 12, 2008 Share Posted April 12, 2008 I would think using the Composite Pattern would be your best choice, here. More info: http://en.wikipedia.org/wiki/Composite_Pattern What this gives is true dynamic rendering based on, say, a List, Map, Hash(array) from any sort of Datasource. I suppose you could add templating on top of that, but I am not experienced with the existing templating engines because I don't like UI work <?php $f = new Form(); $f->setHandler("submit.php"); $f->setAction("POST"); $f->add(new Checkbox("lol")); $f->add(new Input($name="name", $value="Default text")) $f->flush(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/100759-generating-forms-xml-or-php/#findComment-515450 Share on other sites More sharing options...
Mastodont Posted April 13, 2008 Share Posted April 13, 2008 I recommend pure HTML for invariant parts of forms, only dynamic parts should be generated from PHP. $f = new Form(); $f->setHandler("submit.php"); $f->setAction("POST"); Dreadful, if handler is always "submit.php" and action always "POST" ... But if you want to prepare form skeletons and paste their HTML code into final application - this is the way to go. Quote Link to comment https://forums.phpfreaks.com/topic/100759-generating-forms-xml-or-php/#findComment-515961 Share on other sites More sharing options...
keeB Posted April 13, 2008 Share Posted April 13, 2008 But, for a CMS, it surely isn't (always submit/post). If you don't want that complexity, make it in the form constructor with default options? Or initialize it with default options? I was just making a clear example so I don't get asked the opposite: "Where would I set action/method?!" Quote Link to comment https://forums.phpfreaks.com/topic/100759-generating-forms-xml-or-php/#findComment-516202 Share on other sites More sharing options...
Acs Posted April 28, 2008 Share Posted April 28, 2008 When creating forms I always try to use something that will do the code for me! No php classes, but a scaffold system! Which in my opinion is better if you are working with a designer. The code html code is generated and then the designer can do his stuff Quote Link to comment https://forums.phpfreaks.com/topic/100759-generating-forms-xml-or-php/#findComment-528759 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.