SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP redirect after form submit

    Hi,

    I am trying to work out how to create a redirect after a forms submission. I am using the Zoo component with Joomla and currently as frontend form that upon the suibmit button being activated, redirects the user to a clean form with a basic thankyou message. I am trying to instead, have the user redirected to a specific url instead of getting hit with the form again. I have managed to work out that it probably has to do with the following code (part of a bigger picture), but I am a bit green when it comes to PHP... would very much appreciate any ideas or leads....

    kind regards,

    Luke

    PHP Code:
     // set redirect message
                    
    $msg $this->submission->isInTrustedMode() ? JText::_('Thanks for your submission.') : JText::_('Thanks for your submission. It will be reviewed before being posted on the site.');

                    
    // trigger saved event
                    
    $this->app->event->dispatcher->notify($this->app->event->create($this->submission'submission:saved', array('item' => $this->item'new' => !$edit)));

                } else {

                    
    // add post data to session if form is not valid
                    
    $this->app->system->application->setUserState($this->session_form_keyserialize($post));

                }

            } catch (
    SubmissionControllerException $e) {

                
    $error true;

                
    // raise warning on exception
                
    $this->app->error->raiseWarning(0, (string) JText::_($e));

            } catch (
    AppException $e) {

                
    $error true;

                
    // raise warning on exception
                
    $this->app->error->raiseWarning(0JText::_('There was an error saving your submission, please try again later.'));

                
    // add exception details, for super administrators only
                
    if ($this->user->superadmin) {
                    
    $this->app->error->raiseWarning(0, (string) $e);
                }

            }

            
    // redirect to mysubmissions
            
    if ($this->redirectTo == 'mysubmissions' && !$error) {
                
    $link $this->app->route->mysubmissions($this->submission);
            
    // redirect to edit form
            
    } else {
                
    $link $this->app->route->submission($this->submission$this->type->id$this->hash$this->item_id$this->redirectTo);
            }

            
    $this->setRedirect(JRoute::_($linkfalse), $msg);
        }

        public function 
    remove() {

            
    // init vars
            
    $msg null;

            try {

                
    $this->_checkConfig();

                if (!
    $this->submission->isInTrustedMode()) {
                    throw new 
    AppControllerException('The submission is not in Trusted Mode.');
                }

                
    // get item table and delete item
                
    $table $this->app->table->item;

                
    $item $table->get($this->item_id);

                
    // is current user the item owner and does the user have sufficient user rights
                
    if ($item->id && (!$item->canAccess($this->user) || $item->created_by != $this->user->id)) {
                    throw new 
    AppControllerException('You are not allowed to make changes to this item.');
                }

                
    $table->delete($item);

                
    // set redirect message
                
    $msg JText::_('Submission Deleted');

                
    // trigger deleted event
                
    $this->app->event->dispatcher->notify($this->app->event->create($item'submission:deleted'));

            } catch (
    AppException $e) {

                
    // raise warning on exception
                
    $this->app->error->raiseWarning(0JText::_('There was an error deleting your submission, please try again later.'));

                
    // add exception details, for super administrators only
                
    if ($this->user->superadmin) {
                    
    $this->app->error->raiseWarning(0, (string) JText::_($e));
                }

            }

            
    $this->setRedirect(JRoute::_($this->app->route->mysubmissions($this->submission), false), $msg); 

  2. #2
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? I am really stuck here!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •