Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8539905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:28:40+00:00 2026-06-11T11:28:40+00:00

Basically I have an html form for inserting a product. The field names, as

  • 0

Basically I have an html form for inserting a product. The field names, as well as the $_POST vars, are initialized in my Product class. The contructor is “listening” for the submit button. When the user submits the form, the object’s state changes to let’s say “Ready”, which means its attributes are initialized and ready to be inserted into the database.

Then I need to return a message depending on the status of insert (Sucess or Failure), If sucess i’ll print something like “Product Inserted Successfully”, if it fails: “Null fields detected”.

My question is if I’m allowed to put this kind of logic in the view? Like this:

<?php $myproduct = new Product(); ?>

<form>
<!-- Fields -->
</form>

<?php
if ($myproduct->ready()) :
    if ($myproduct->insert()) : ?>
        <p>Product inserted successfully</p>
<?php
    else : ?>
        <p>Null fields detected</p>
<?php
    endif;
endif; ?>

I really can’t think of a simpler way, since I really need to show the message depending on the insert() return status.

So is it allowed in the MVC pattern to mix that kind of logic in the view? I’m not exposing any kind of business logic, just checking the object’s status.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T11:28:41+00:00Added an answer on June 11, 2026 at 11:28 am

    No. The domain business logic has no place in the view (nor in the presentation layer as whole). That’s why MVC has the model layer.

    When you are submitting a form, the order of operations should be as following:

    1. controller receives the request with $_POST data

    2. controller sends the information to the model layer

      • if data is valid, model layer saves the information
      • if data is invalid, model layer sets and acquires error state and saves it (usually in session)
    3. controller notifies current view that there was POST sent

    4. when view is requested to generate response (preferably, not by controller), it sends a Location HTTP header (to prevent double-posting)

    5. controller receives new request (with only GET parameter this time)

    6. if required, controller adjusts state of model layer and current view

    7. view inquires model layer whether it contains error state

      • if there is error state, view requests list of error code from model layer and based on that information chooses, which templates to use to compose a form with “error” messages
      • if there is no error state in model layer, view uses templates to create a “success” message

    There would be the order of operations for form submission in Model2 MVC pattern.

    Depending on whether you display error messages and/or success messages in the same view as the form itself, the view instance might check the model layer for error state in STEP 4. Then view could decide which Location header to send.

    P.S. The interaction with model layer would most likely happens through service.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I have something like this <div class=iframe-holder> <span></span> <iframe src=iframe.html width=200 height=200
I have a html form that is basically vertical but i really have no
So basically there is a made html form with a button, it doesnt have
In this html I basically have a sidebar-div and a page-div with the header,
I have an html-like xml, basically it is html. I need to get the
I have those two html radio buttons and textarea. I basically want to enable
I have php generating html and I want to create layers. Basically I want
I have a 'template' system in my CMS rails app. Basically the whole HTML
I have a query that is more complicated, but basically creates an HTML page
I would like to add a preprocessor to HTML pages. Basically, I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.