Ansego Posted March 16, 2014 Share Posted March 16, 2014 Hello all; might be a silly question but I need to ask it, I end up with 1000+ lines of code for 10 field forms, thinking to myself this cant be right, defiantly not using the KISS principle!, so I want to try using classes and not 100% on structure or use and hoping they may make my life easier. Below is MOCK up code and my questions are: Q: Is this best practise? (form->handler->classes->db) REF BELOW CODE! Q: How do you guys handle your forms -> classes -> db? Q: What is best practise? Q: In PAGE: index.php should it be including all 3 other pages? is that how you include a class? Q: Please share rules and thumbs, hints, theories, methodologies etc etc... MOCK CODE - CODE NOT TESTED & Prob won't work just general mock for structure and logic: PAGE: INDEX.PHP (MOCK CODE) include 'inc/frm_handler.inc.inc'; include 'inc/check_class.inc'; include 'inc/dbhandler_class.inc'; <form...> <input name='test' type='text' value=''/> <input type='button' value='&Submit'/> </form> PAGE: FORM_HANDLER.INC (MOCK CODE) $testcheck = new testcheck(); $myvar = $_Post['test']; if ($testcheck.test_check($myvar) == true){ $dbsqlsend = new dbsqlexecute(); $dbsqlsend.executeSQL($myvar); } PAGE: CHECK_CLASS.INC (MOCK CODE) class testcheck{ public test_check($str_check){ if (filter_var($str_check, FILTER_SANITIZE_STRING)){ return true; } else { return false; }; }; }; PAGE: DBHANDLER_CLASS.INC (MOCK CODE) class dbsqlexecute{ public executeSQL($str_sql){ // EXECUTE MYSQLI CODE HERE ETC }; }; Link to comment https://forums.phpfreaks.com/topic/287008-class-what-is-best-practise-form-handler-class-db/ Share on other sites More sharing options...
trq Posted March 16, 2014 Share Posted March 16, 2014 Q: Is this best practise? (form->handler->classes->db) REF BELOW CODE! It is one way of handling things, and is probably pretty close to how most frameworks would handle it. Q: How do you guys handle your forms -> classes -> db? Most frameworks have some form of "form" handling built in. Q: What is best practise? Don't reinvent the wheel. Q: In PAGE: index.php should it be including all 3 other pages? is that how you include a class? No and No. Classes should be auto loaded using an autoloader (see spl_autload) Link to comment https://forums.phpfreaks.com/topic/287008-class-what-is-best-practise-form-handler-class-db/#findComment-1472770 Share on other sites More sharing options...
Ansego Posted March 16, 2014 Author Share Posted March 16, 2014 Thanks mate. Link to comment https://forums.phpfreaks.com/topic/287008-class-what-is-best-practise-form-handler-class-db/#findComment-1472783 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.