Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,940
    Plugin Contributions
    96

    Default Re: Attribute Text Custom Validation

    You could create the file /includes/extra_cart_actions/validate.php. Note that this file can be named anything you want; it just needs to be in this directory.

    In this file, you could check for the cart-related action (add-to-cart is the only one you need to care about, since your products have attributes). If attributes are included in the POST data (the 'id' values), then check for the VIN-related option name/value pair (you can see their values in your admin's Attribute Controller). If an error exists with the data, write a message to the header (so it will be seen on all pages) and then redirect to the return-page for the cart-related actions.

    Best thing: No core file overrides.

    Code:
    <?php
    global $messageStack;
    
    if ($_GET['action'] == 'add_product') {
     
      /*---- Add a product to cart ----
      */
        if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0) {
          if (isset($_POST['id'])) {
            foreach($_POST['id'] as $option => $value) {
              if ($option == VIN_OPTION_NUMBER) {
                <do some checking on the vin entered>
                 if( $vin_error) {
                   $messageStack->add_session('header', ERROR_VIN_ERROR);
                   zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
                 }
               }
            }
          }
        }      
    }

  2. #2
    Join Date
    Nov 2010
    Posts
    68
    Plugin Contributions
    0

    Default Re: Attribute Text Custom Validation

    Cool. I think that's what I needed to get the ball rolling.



    ---JC


    Quote Originally Posted by lat9 View Post
    You could create the file /includes/extra_cart_actions/validate.php. Note that this file can be named anything you want; it just needs to be in this directory.

    In this file, you could check for the cart-related action (add-to-cart is the only one you need to care about, since your products have attributes). If attributes are included in the POST data (the 'id' values), then check for the VIN-related option name/value pair (you can see their values in your admin's Attribute Controller). If an error exists with the data, write a message to the header (so it will be seen on all pages) and then redirect to the return-page for the cart-related actions.

    Best thing: No core file overrides.

    Code:
    <?php
    global $messageStack;
    
    if ($_GET['action'] == 'add_product') {
     
      /*---- Add a product to cart ----
      */
        if (isset($_POST['products_id']) && $_POST['cart_quantity'] > 0) {
          if (isset($_POST['id'])) {
            foreach($_POST['id'] as $option => $value) {
              if ($option == VIN_OPTION_NUMBER) {
                <do some checking on the vin entered>
                 if( $vin_error) {
                   $messageStack->add_session('header', ERROR_VIN_ERROR);
                   zen_redirect(zen_href_link($goto, zen_get_all_get_params($parameters)));
                 }
               }
            }
          }
        }      
    }

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,940
    Plugin Contributions
    96

    Default Re: Attribute Text Custom Validation

    You can also take a peek at /includes/main_cart_actions.php to get a feel for the attribute-handling.

 

 

Similar Threads

  1. Attribute Cross-Validation
    By pizza392 in forum Setting Up Categories, Products, Attributes
    Replies: 5
    Last Post: 25 Oct 2013, 11:47 AM
  2. Custom Form Field and Email Validation
    By zepher in forum Managing Customers and Orders
    Replies: 4
    Last Post: 26 Jan 2010, 12:45 AM
  3. Custom form: Field Validation
    By amites in forum General Questions
    Replies: 3
    Last Post: 8 Jun 2007, 02:37 PM
  4. validation for attribute
    By vr4indian in forum Setting Up Categories, Products, Attributes
    Replies: 7
    Last Post: 8 Aug 2006, 05:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg