Created a model in which the form validation on the beck

  public function validation_form()
    $error = false;
    if (!Zend_Validate::is($name, 'NotEmpty')) {
        $error = Mage::getSingleton('core/session')->addError('Name is required');
    if (!Zend_Validate::is($message, 'NotEmpty')) {
        $error = Mage::getSingleton('core/session')->addError('Message is required');
    if (!Zend_Validate::is($subject, 'NotEmpty')) {
        $error = Mage::getSingleton('core/session')->addError('Subject is required');
    if (!Zend_Validate::is($email, 'EmailAddress')) {
        $error = Mage::getSingleton('core/session')->addError('Email is required');
    if ($error) {
        throw new Exception();

And there is a method in the controller that adds data to the database.

 public function postAction()
    $post = $this->getRequest()->getPost();
            if ($post) {

                $name = $this->getRequest()->getPost('name');
                $email = (string)$this->getRequest()->getPost('email');
                $phone = $this->getRequest()->getPost('phone');
                $user_agent = Mage::helper('core/http')->getHttpUserAgent();
                $remote_ip = Mage::helper('core/http')->getRemoteAddr();
                $subject = $this->getRequest()->getPost('subject');
                $other_subject = $this->getRequest()->getPost('other');
                $message = $this->getRequest()->getPost('message');
                $created_at = Mage::getModel('core/date')->date('Y-m-d H:i:s');

How to connect function postAction() to validation so that the variables "$name, $email, etc..." are available in the validation model.

Path to the controller mymodul/feedback/controllers/IndexController.php

Path to the validation mymodul/feedback/model/Validation.php


I see several issues here:

  1. your method validation_form() does not take any parameters. It should be something like public function validation_form($name, $message, $subject, $email). Else, the method does not have access to any of the values from postAction().

  2. I don't knot if you can throw an Exception() with an empty message, and I'm not sure if the validate_form() method will work as expected, but you can try and open another question if new errors occur :)

  3. From your postAction(), call the method like this:

Mage::getModel('mymodule/validation')->validate_form($name, $message, $subject, $email);

...assuming you defined your model namespace in your config.xml file. If you didn't, search for a tutorial how to define a basic Magento 1 module - it's easy ;)

|improve this answer|||||
  • Thanks, passed the values to the function and it all worked, thanks again) – Рома Лытарь Feb 25 '19 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.