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

  • SEARCH
  • Home
  • 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 8637027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:22:29+00:00 2026-06-12T10:22:29+00:00

I have a view which interacts with more than one controller (post, comments, categories…)

  • 0

I have a view which interacts with more than one controller (post, comments, categories…)

In case the comment is not empty, it would go to the same action (comments/add) but in this case i manually redirect them again to the previous view with something like this:

$this->redirect(array('controller' => 'posts', 'action' => 'view', $this->request->data['Comment']['posts_id'], '#' => $this->Comment->id));

The thing is, when they try to post an empty comment, for example, the validation of Comment redirects it to comments/add (which is the route on the form action) but i don’t want the redirection to do this. I want it to come back to the original view and i don’t have anyway to change it on the controller or the model (as far as I know)

Is there any way to do this?

Thanks.

  • 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-12T10:22:31+00:00Added an answer on June 12, 2026 at 10:22 am

    The easiest way to do this is to make your form submit via AJAX. So you don’t refresh the whole page on submit – you just get the form back, with errors (if there are any).

    Obviously, that won’t work for users without Javascript. So you can either not worry about those users, or you can make it so the add method of your comments controller uses the view that you want. Something like this:

    if ($this->request->is('ajax')) {
        $this->render('/Elements/comment_form');
        return;  // return the form only
    } else {
        $this->render('/Posts/view'); // Your post view.ctp would have the comment form on it.
    }
    

    Here’s an example of a page where I’ve used that method: http://www.lintonmeagher.com/contact Try submitting either one of the forms with no data.

    Let me know if you need any more info.

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

Sidebar

Related Questions

i have view controller which contains a button which show the image library ,if
Lets assume I have the following 3 entities: Customer,Order,Product which interact in the View
I have view on which I defined a custom tagName. I need to be
I have a view which I would like to fill up the entire screen
I have a view which has two labels. When I swipe left I fill
I have a view which is composed of top, left and bottom headers and
I have a view which was working fine when I was joining my main
I have a view which I built in Interface builder with a tableview and
I have 5 view which have deferent json data , in all my 5
I have a view with two subviews: A UIImageView A small Custom View which

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.