yellowepi Posted April 28, 2007 Share Posted April 28, 2007 I don't know if this is the best way to develop a form dynamically or not, but this is the way I did. I made an array and used the keys and values to fill in to make the form. [red] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <table><form> <?php $forminput = array( "Username" => "username", "First Name" => "fname", "Last Name" => "lname", ); foreach ($forminput as $field => $value) { echo "<tr><td>" .$field . ": </td> <td><input type='text' name='" .$value."'></td></tr>"; } ?> </form></table> </body> </html> Is this the best way for creation of a form, or are there better ways. I am new to programming and feel pretty good about this one, but since I am new I am sure there are better ways. Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/ Share on other sites More sharing options...
flappy_warbucks Posted April 28, 2007 Share Posted April 28, 2007 I dont see any problem with that... its nice and simple and it gets the job done to your satiisfaction... if it aint broke dont fix it Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/#findComment-240410 Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 There are never better ways, there are only "easier-to-maintain" ways, for example, you could seperate your presentation from your business logic using templates, i am not a real fan of having html running around in my php code! Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/#findComment-240432 Share on other sites More sharing options...
yellowepi Posted April 28, 2007 Author Share Posted April 28, 2007 I'm still very new at using php, and have heard of seperating all of this out. I know there are prebuilt templates like smarty etc, but how would you code this to make your own template? If it would take to long to explain-just say so and I will try to figure it out. Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/#findComment-240437 Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 how i would code this? using smarty: login.tpl {include file = 'header.tpl'} <form action='{$action}' method='post'> <table border="0"> <tr> <td><label for='{$lblUsername}'>{$txtUsername}</label></td> <td><input type='text' id='{$lblUsername}' name='{$lblUsername}' maxlength='25' /></td> </tr> <tr> <td><label for='{$lblPassword}'>{$txtPassword}</label></td> <td><input ... </tr> </table> </form> {include file='footer.tpl'} login.php $oSmarty = new Smarty; $oSmarty->assign('action', ''); $oSmarty->assign('lblUsername', 'username'); // If you are using PEAR packages like Auth, this would be something like: // $oSmarty->assign('lblUsername', $oAuth->getPostUsernameField()); $oSmarty->assign('txtUsername', 'Username:'); ... $oSmarty->display('login.tpl'); Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/#findComment-240479 Share on other sites More sharing options...
ignace Posted April 28, 2007 Share Posted April 28, 2007 If you wanna program your own, i suggest reading about MVC (model-view-controller) framework, and starting by using CakePHP and CodeIgniter Quote Link to comment https://forums.phpfreaks.com/topic/49067-dynamic-form-creation-question/#findComment-240491 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.