Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/
Share on other sites

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?

 

Link to comment
https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944832
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944864
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944971
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/179066-create-forms-in-mvc/#findComment-944998
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.