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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:27:41+00:00 2026-06-02T21:27:41+00:00

I have two contact forms in my CakePHP application — one with its own

  • 0

I have two contact forms in my CakePHP application — one with its own Controller, Model, and View, and another one in an element that can be accessed as a “quick” contact form from the footer of every page on the site.

The code for both forms is the same. The element is intended to access the Controller and Model that the other form uses. However, the element is not submitting the data or sending the email, while the regular page works just fine.

Here is the MVC Code for the regular form that IS working:

<!-- Model: Model/Contact.php -->

<?php
class Contact extends AppModel {
    var $name = 'Contacts';
    public $useTable = false;  // Not using the database, of course.

    var $validate = array(
        'name' => array(
            'rule' => '/.+/',
            'allowEmpty' => false,
            'required' => true,
        ),
        'email' => array(
            'allowEmpty' => false,
            'required' => true,
        )
    );

    function schema() {
        return array (
            'name' => array('type' => 'string', 'length' => 60, 'class' => 'contact input'),
            'email' => array('type' => 'string', 'length' => 60, 'class' => 'contact input'),
            'message' => array('type' => 'text', 'length' => 2000, 'class' => 'contact input'),
        );
    }

}
?>

<!-- Controller: Controller/ContactsController.php -->

class ContactsController extends AppController
{
    var $name = 'Contacts';
    /* var $uses = 'Contact'; */
    var $helpers = array('Html', 'Form', 'Js');
    var $components = array('Email', 'Session');

    public function index() {
        if(isset($this->data['Contact'])) {
            $userEmail = $this->data['Contact']['email'];
            $userMessage = $this->data['Contact']['message'];

            $email = new CakeEmail();
            $email->from(array($userEmail));
            $email->to('email@example.com');
            $email->subject('Website Contact Form Submission');
            $email->send($userMessage);

            if ($email->send($userMessage)) {
                $this->Session->setFlash('Thank you for contacting us');
            } 
            else {
                $this->Session->setFlash('Mail Not Sent');
            }

        }
    }

    public function contact() {
        if(isset($this->data['Contact'])) {
            $userEmail = $this->data['Contact']['email'];
            $userMessage = $this->data['Contact']['message'];

            $email = new CakeEmail();
            $email->from(array($userEmail));
            $email->to('email@example.com');
            $email->subject('Website Contact Form Submission');
            $email->send($userMessage);

            if ($email->send($userMessage)) {
                $this->Session->setFlash('Thank you for contacting us');
            //  $this->redirect(array('controller' => 'pages', 'action' => 'index'));
            } 
            else {
                $this->Session->setFlash('Mail Not Sent');
            }

        }
    }

}
?>

<!-- View: Views/Contacts/index.ctp -->

<? 
$main = 'contact';
$title = 'quick contact';
?>
<div style="border-bottom: solid 1px #ccc;">
    <h1 style="position:relative; float:left;"><?php echo $main; ?></h1>
    <h2 style="position:relative;float:left;margin-top:15px; color: #869c38">&nbsp; &bull;&nbsp; <?php echo $title;?></h2>
    <br><br>&nbsp; &nbsp; 
</div>
<div class="clear"><br></div>
<div id="interior-page">
    <?php

    echo $this->Form->create('Contact');
    echo $this->Form->input('name', array('default' => 'name (required)', 'onfocus' => 'clearDefault(this)'));
    echo $this->Form->input('email', array('default' => 'email (required)', 'onfocus' => 'clearDefault(this)'));
    echo $this->Form->input('message', array('default' => 'message', 'onfocus' => 'clearDefault(this)'));
    echo $this->Form->submit();
    echo $this->Form->end();
    ?>
</div>

And here is the view for the quick contact form that is NOT working, located in an element displayed in the footer of the default layout:

<?php

echo $this->Form->create('Contact');
echo $this->Form->input('name', array('default' => 'name (required)', 'onfocus' => 'clearDefault(this)'));
echo $this->Form->input('email', array('default' => 'email (required)', 'onfocus' => 'clearDefault(this)'));
echo $this->Form->input('message', array('default' => 'message', 'onfocus' => 'clearDefault(this)'));
echo $this->Form->submit();
echo $this->Form->end();

?>

I tried different ways of changing the form action, but I couldn’t figure that out.

  • 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-02T21:27:42+00:00Added an answer on June 2, 2026 at 9:27 pm

    Usually, cake “automagically” creates the action of the form based on where you call it from E.g. if called from the view Views/Contacts/index.ctp, it will set the action to /contacts/index. In case of an element, Cake can’t really guess what you’re trying to do, so you need to set the action manually:

    $this->Form->create('Contact', array('action' => 'index'));
    

    Or set the full URL alternatively:

    $this->Form->create('Contact', array('url' => '/contacts/index'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery Validation JS I have two contact forms, the main one
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have three models: System_Contact System Contact_list The Contact_List model has two fields: contact
I have two files the one which hosts my actual contact form and then
I have two user controls (ascx); one contains some forms, and the other one
I have three forms on one page - callback, contact us and newsletter subscription.
I have two tables: Contact (id,name) Link (id, contact_id, source_id) I have the following
I have a 'Contact' class with two properties : firstName and lastName. When I
I have two DropDownListBoxes one is called ddlDay and the other is ddlMonth. As
I have two application that need to talk to each other. App1 needs to

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.