• info@synamen.com
  • +91-89396 79369
  • Reach Us
synamen-logo
  • Home
  • Solutions
    E-Commerce Development Magento E-Commerce Management Mobile App Development Oracle Cloud Solutions
  • Products
    Splurgify for M-commerce MeterDesk -Energy Management & Industrial Analytics Enquiry Management System
  • Portfolio
  • Company
    About Us Our Team News Reach Us
  • Careers
  • Blog

Home >> Blog >> Currency name required only when the amount is entered

yii-student-portal

25 Sep 2017

Currency name required only when the amount is entered

Posted By : AdminPerson YII

Scenario: On any application development the transaction related forms shall have currency field (if the application intended to support multiple currencies), which should become mandatory only when the amount is available

Detailed Description: Yii is a high-performance PHP framework best for developing Web 2.0 applications. Yii comes with rich features: MVC, DAO/ActiveRecord, I18N/L10N, caching, authentication and role-based access control, scaffolding, testing, etc. As a rule of thumb, you should never trust the data received from end users and should always validate it before putting it to good use. To validate attributes only when certain conditions apply, e.g. the validation of one attribute depends on the value of another attribute, in transaction forms, currency name or code is mandatory if the amount is available to convert or calculate the equivalent amount in base currency.

Solution:

Step -1: Open the model for which the validation is required in order to modify the rule. Assume payment as table name, and the model name should be payment.php; In the basic template, the path is app/models/payment.php; In advanced template the path is common/models/payment.php Step -2: Find function called rules() and insert the below code within return[] array. Add ',' at an appropriate place if there are existing attribute rules. Eg: if you are adding the code after the existing rule, use ',' before the code start. ['currency', 'required', //This is server side validation 'when' => function ($model) { if(empty($model->amount)) { return false; }else { //Error will thrown return true; } }, //This is for client side validation 'whenClient' => "function (attribute, amount) { if($('#model-amount').val()=='' || $('#model-amount').val()==null) { return false; }else { //Error will thrown return true; } }" ] Step -3: Now the rules will be applied in the form validation related to this model in both client side and server side.

Share this Article on

  • Facebook
  • Twitter
  • LinkedIn

Tags: form rules , form validation , yii


Related Posts

Archive

  • 2022

    September

    July

    April

    March

    February

  • 2019

    March

    February

    January

  • 2018

    December

    November

    October

    September

    August

    July

    June

    March

    February

    January

  • 2017

    December

    November

    October

    September

    August

    July

    June

    May

    April

    March

    February

  • 2013

    December

    September

Tags

add new condition in shopping cart admin admob analytics artificial intelligence augmented information augmented reality automation avoid jquery b2b b2b business b2c bounce rate bvp corporate crawling custom catalogs custom shopping cart price rule customer customer engagement customer satisfaction digital marketing e-commerce e-commerce checkout ecommerce customer experience erp form rules form validation generic google ranking google search googlebot http https hybrid ideas innovation international ionic javascript m-commerce machine learning magento magento e-commerce magento pwa studio mobile advertising platform mobile app development mobile application mobile apps mobile commerce strategy
Synamen-logo

Synamen is an Internet consulting company focusing on efficient use of Internet and Web technologies in business. We are into E-Commerce Development, Magento Development and Mobile App Development Services.

Read More

Solutions

  • E-Commerce Development
  • Magento E-Commerce Management
  • Mobile App Development
  • Oracle Cloud Solutions

Products

  • Mobile E-Commerce Solution
  • Energy Management & Industrial Analytics
  • Enquiry Management System

Reach Us

  • Synamen Thinklabs Pvt Ltd
    #7, Second Floor, Seetha Nagar Main Road, Nungambakkam, Chennai - 600034. India.
  • +91-89396 79369
  • info@synamen.com

© 2007 - Synamen Thinklabs Pvt Ltd. All rights reserved     Privacy Policy