0
votes

I want redirect to two pages one is view part another one is index part .

Example : I am going to add new user. After i click submit button . The page has direct to index page in new tab and one more redirect is view part . Currently its redirect to only index function . I want to reidrect to both index and view function in two separate or else in pop up window .

Controller:

 public function add() {
            if ($this->request->is('post')) {
                $this->User->create();
                if ($this->User->save($this->request->data)) {
                    $this->Session->setFlash(__('The user has been saved'));
                    $this->redirect(array('action' => 'index'));
                } else {
                    $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
                }
            }
        }

View:

<div id="content">
    <div id="flashMessage" class="message">The user could not be saved. Please, try again.</div>
    <div class="users form">
        <form action="/login/users/add" id="UserAddForm" method="post" accept-charset="utf-8">
        <div style="display:none;">
            <input type="hidden" name="_method" value="POST">
        </div>
        <fieldset>
            <legend>Add User</legend>
            <div class="input text required">
                <label for="UserUsername">Username</label>
                <input name="data[User][username]" maxlength="128" type="text" value="[email protected]" id="UserUsername">
            </div>
            <div class="input password required">
                <label for="UserPassword">Password</label>
                <input name="data[User][password]" type="password" value="vtuadmin" id="UserPassword">
            </div>
            <div class="input text required">
                <label for="UserRole">Role</label>
                <input name="data[User][role]" maxlength="20" type="text" value="admin" id="UserRole">
            </div>
            <div class="input text required error">
                <label for="UserRole1">Role1</label>
                <input name="data[User][role1]" type="text" value="" id="UserRole1" class="form-error">
                <div class="error-message">Please enter a valid role11111</div>
            </div>
        </fieldset>
        <input type="submit">
        </form>
    </div>
</div>
1

1 Answers

2
votes

Try This :

Controller:

public function add() {
        if ($this->request->is('post')) {
            $flag='0';
            $this->User->create();
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved'));
                $flag='1';
                $this->set(compact('flag'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        }
    }

View:

if($flag == 1){
  //Use Jquery window.open()/
}

window.open ref link is : Click me