Omzy Posted October 26, 2009 Share Posted October 26, 2009 I'm looking to rewrite all my forms using the MVC concept, I've tried searching Google for help on this but there isn't anything useful/relevant! So let's suppose I want to create a simple form with fields login and password. These fields also need to be validated. Can someone give me a BASIC idea of how the code should be written, using the MVC concept. Regards. Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/ Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 wikipedia has a good base for understanding this concept. Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944769 Share on other sites More sharing options...
Omzy Posted October 26, 2009 Author Share Posted October 26, 2009 I understand the concept, I just want to see it in practice, i.e. a form based on MVC (as described above) Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944776 Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 examples of MANY different implementations can be found on wikipedia (as mentioned above) Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944783 Share on other sites More sharing options...
Omzy Posted October 26, 2009 Author Share Posted October 26, 2009 I'm not after a framework, all I want to see is some sample code which I can understand and build upon to create a fully featured MVC form. Can anyone else help? Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944792 Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 I could be wrong here, but using the MVC pattern for form processing might be a bit overkill and is probably not how you want to go about learning it. Then again, I am not familiar with what your end-goal is. If you are trying to write very reusable/readable/modifiable code but you can't go wrong starting with a framework. Once you understand one of these framework's you will be able to do much more than write a form processor (which already exists and you don't need to code). The example you are looking for is undoubtedly in one of those frameworks out there. The zend framework comes highly recommended on this forum - although I have yet to write any useful code with it - it is very solid and well documented. It will be overwhelming, I am still in the process of learning the zend framework. Are you familiar with Object Oriented PHP or Object Oriented Programming in general? If not, the PHP freaks OOP tutorial is wonderful. What exactly are you aiming to do? Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944832 Share on other sites More sharing options...
Omzy Posted October 26, 2009 Author Share Posted October 26, 2009 Using a framework is exactly what I DON'T want to do. All I want to do is apply the concepts of MVC to my current applications. These applications are not massive, they are relatively small. A framework comes with far too much baggage and is too much overkill, so I'd rather just code my own functions. For example my current site is handcoded with PHP and XHTML all in the same file, there is no separation of business logic and presentation logic whatsoever. But the whole site consists of only 16 PHP files in total. I know once I start MVCing my site I will probably end up with 3x more files than I currently have but that's not as bad as implementing a framework which consists of hundreds of files (the majority of which I'll probably never use). I know frameworks do have their advantages and are designed as a "one for all" solution but I'd rather just code exactly what I need to myself! Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944864 Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 What made you decide to switch to the MVC pattern? -just curious Check out this article -it may help, although it is written for a different programming language its the closest i've found to what (i think) you are looking for. You might have more luck with help on this topic if you try a little development on your own. you won't get the results you are looking for simply saying, "I don't understand this, what should the code look like?" If you are having trouble before you even start coding I suggest you read some articles of developing in MVC. (here's another) Google MVC, PHP - plenty of documentation. are you just having trouble on where to start...or...? because wikipedia, google, whatever should give you a BASIC idea of what the code should look like. Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944971 Share on other sites More sharing options...
Derleek Posted October 26, 2009 Share Posted October 26, 2009 also, if you start to develop in MVC - you are creating your own framework.... essentially. Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944972 Share on other sites More sharing options...
KevinM1 Posted October 26, 2009 Share Posted October 26, 2009 A quick idea would be: User arrives at your site. Since they're there for the first time, there's no action to process, so the controller displays the default page, which includes your login form. Once the user enters their info, it's sent to the controller (most likely through a postback). The controller then decides what to do (was the user attempting to log in? write a comment? etc), and funnels it to the mechanism that will validate the data. The data is either accepted, and the user is successfully logged in, or rejected, and the user is denied. Either way, the logic updates the page (view) with the status of the login attempt. So, essentially, you'll have a controller sitting 'on top' of your application, retrieving request data and sending it to the right sub-system to be processed. The sub-system will then update the view, either directly, or through the controller. Quote Link to comment https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944998 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.