casperino Posted October 5, 2017 Share Posted October 5, 2017 (edited) Hello, could you please advise me how can I set up all fields in contact form as mandatory? Thank you very much in advance. Edited October 8, 2017 by casperino (see edit history) Link to comment Share on other sites More sharing options...
casperino Posted October 6, 2017 Author Share Posted October 6, 2017 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 More sharing options...
casperino Posted October 6, 2017 Author Share Posted October 6, 2017 (edited) Hi, sorry, but still no change. Only text area + email address are mandatory... Edited October 6, 2017 by casperino (see edit history) Link to comment Share on other sites More sharing options...
casperino Posted October 6, 2017 Author Share Posted October 6, 2017 There are only 2 errors If I not fill email address and text area. When I fill them, the message has been sent. Link to comment Share on other sites More sharing options...
casperino Posted October 7, 2017 Author Share Posted October 7, 2017 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 More sharing options...
joel Posted May 29, 2018 Share Posted May 29, 2018 /** * @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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now