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 6173541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:35:39+00:00 2026-05-23T23:35:39+00:00

I have built a contact form using CakePHP on my site. The controller logic

  • 0

I have built a contact form using CakePHP on my site. The controller logic is as follows:

<?php

class ContactController extends AppController
{
    var $helpers = array ('Html','Form');

    var $components = array ('Email','RequestHandler');

    var $name = 'Contact';

    function beforeFilter()
    {
        parent::beforeFilter();

        $this->Auth->allow(array('*'));  
    }

    function index()
    {
        if ($this->RequestHandler->isPost())
        {
            $this->Contact->set($this->data);
            if ($this->Contact->validates())
            {
                $this->Email->to = '###';  
                $this->Email->subject = 'Contact message from ' . $this->data['Contact']['name'];  
                $this->Email->from = $this->data['Contact']['email'];  

                $this->Email->send($this->data['Contact']['message']);

                $this->render('success');
            }
        }
    }

}

?>

What I want to do is when a user submits the form is show another view file such as success.ctp but what happens is even though they have a new view they could refresh the page and send the data again and again. How do I stop this…

Can anyone help? 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-05-23T23:35:40+00:00Added an answer on May 23, 2026 at 11:35 pm

    after you process their form data, redirect them to the same contact page (to avoid the refresh problem)

    If you’re not aware, you can setFlash to show a success message. But if you want to customize it the way you want, you can write a variable to Session to signal the view.

    function index()
    {
        if ($this->RequestHandler->isPost())
        {
            $this->Contact->set($this->data);
            if ($this->Contact->validates())
            {
                $this->Email->to = '###';  
                $this->Email->subject = 'Contact message from ' . $this->data['Contact']['name'];  
                $this->Email->from = $this->data['Contact']['email'];  
                $this->Email->send($this->data['Contact']['message']);
                $this->Session->write('Contact.postmessage', true);
                $this->redirect(array('action'=>'index'));
            }
        }
        $this->Session->delete('Contact.postmessage');
    }
    

    And in the view:

    if($this->Session->check('Contact.postmessage'){
       // write out content of success.ctp
      }else{
       // write out form
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a contact form in PHP inside a Wordpress page, using the exec-php
I have just built my first PHP contact form with validation and yet it
i have bought a template that have built in contact form problem is that
I have built a web page which contains a Crystal Report built using the
I have built a number of asp.net servercontrols into a class library, & I
I want to build my WP theme with a built in contact form. Something
I'm setting up a contact form, but I have some saved information in some
When picking out contact details, is there a built in domain class they can
I am pulling me hair out about this one. http://www.nettunes.co.za/build/contact.php I have an image
I built a site using Drupal 6 recently that allows for users to submit

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.