Jump to content

[SOLVED] Mandatory fields in Contact Form


casperino

Recommended Posts

Hi,

I tired it, but no change. Please see my full contact.php

 

 

 

class ContactCore extends ObjectModel

{

    public $id;

 

    /** @var string Name */

    public $name;

    /** @var string e-mail */

    public $email;

 

    /** @var string Detailed description */

    public $description;

    public $customer_service;

    /**

     * @see ObjectModel::$definition

     */

    public static $definition = array(

        'table' => 'contact',

        'primary' => 'id_contact',

        'multilang' => true,

        'fields' => array(

            'email' =>                array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128, 'required'=>true),

            'customer_service' =>    array('type' => self::TYPE_BOOL, 'validate' => 'isBool'),

 

            /* Lang fields */

            'name' =>                array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),

            'description' =>        array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml', 'required'=>true),

        ),

    );

 

    /**

     * Return available contacts

     *

     * @param int $id_lang Language ID

     * @param Context

     * @return array Contacts

     */

    public static function getContacts($id_lang)

    {

        $shop_ids = Shop::getContextListShopID();

        $sql = 'SELECT *

    FROM `'._DB_PREFIX_.'contact` c

    '.Shop::addSqlAssociation('contact', 'c', false).'

    LEFT JOIN `'._DB_PREFIX_.'contact_lang` cl ON (c.`id_contact` = cl.`id_contact`)

    WHERE cl.`id_lang` = '.(int)$id_lang.'

    AND contact_shop.`id_shop` IN ('.implode(', ', array_map('intval', $shop_ids)).')

    GROUP BY c.`id_contact`

    ORDER BY `name` ASC';

        return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

    }

    /**

     * Return available categories contacts

     * @return array Contacts

     */

    public static function getCategoriesContacts()

    {

        $shop_ids = Shop::getContextListShopID();

        return Db::getInstance()->executeS('

   SELECT cl.*

   FROM '._DB_PREFIX_.'contact ct

   '.Shop::addSqlAssociation('contact', 'ct', false).'

   LEFT JOIN '._DB_PREFIX_.'contact_lang cl

    ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.')

   WHERE ct.customer_service = 1

   AND contact_shop.`id_shop` IN ('.implode(', ', array_map('intval', $shop_ids)).')

   GROUP BY ct.`id_contact`

  ');

Link to comment
Share on other sites

I am sorry but I do not understand, what you mean automatically? 

 

Contact form contains 5 fileds:

 

1.Name

2.Email address

3.Phone number

4.Reference number

5.Text area

 

Only 1st and 2nd are mandatory, the rest ones if you not fill the message has been sent. That´s why I am asking how to set up the same rule (mandatory) also for rest 3 fields.

 

Thank you.

Link to comment
Share on other sites

  • 7 months later...
/**
	 * @see ObjectModel::$definition
	 */
	public static $definition = array(
		'table' => 'contact',
		'primary' => 'id_contact',
		'multilang' => true,
		'fields' => array(
			'email' => 				array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128,'required' => true,),
			'customer_service' => 	array('type' => self::TYPE_BOOL, 'validate' => 'isBool','required' => true,),

			// Lang fields
			'name' => 				array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
			'description' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml''required' => true,),
		),
	);

here place defenition for other 3 fields


/**
	 * @see ObjectModel::$definition
	 */
	public static $definition = array(
		'table' => 'contact',
		'primary' => 'id_contact',
		'multilang' => true,
		'fields' => array(
			'email' => 				array('type' => self::TYPE_STRING, 'validate' => 'isEmail', 'size' => 128,'required' => true,),
			'customer_service' => 	array('type' => self::TYPE_BOOL, 'validate' => 'isBool','required' => true,),

			// Lang fields
			'name' => 				array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 32),
			'description' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCleanHtml''required' => true,),

			//Number field
			'number' => 				array('type' => self::TYPE_NUMBER, 'validate' => 'isContact', 'size' => 12,'required' => true,),
		),
			//Reference field
			'number' => 				array('type' => self::TYPE_NUMBER, 'validate' => 'isReference', 'size' => 12,'required' => true,),
			//Message field
			'message' => 				array('type' => self::TYPE_STRING, 'validate' => 'isCleanHTML', 'size' => 50,'required' => true,),
	);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...