Magento custom form validation

Share
Posted on May 8th, 2013 | Posted by admin

Custom validation method

Adding a new validation rule into a form in Magento is easy as adding a “required” class for a input form. While existing validation rules can be seen in file js/prototype/prototype.js there is an easy way to add your own validation rule.

Add following inline JavaScript into template or load it in separate file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<script type="text/javascript">
//<![CDATA[
Validation.add('required-classname','<?php echo __('Please enter valid value.'); ?>',function(value){
if(value == null)
{
return false;
}
/*
* Your code here
* Return true if you like the value
*/
});
//]]>
</script>

First parameter is the classname for your input element. The second parameter is the error message for invalid input. Third parameter is a function where your code lies. The function should return false on invalid value.

Adding a ‘New Product’ icon in Magento for new products

Share
Posted on April 19th, 2013 | Posted by admin

his is actually quick and easy but if you are new to Magento custom attributes you might struggle to work out how to set things up and then access the value of your attribute on the front end.

What I am talking about here is setting up a flag for the product, if it’s set to ‘Yes’ (ie the product is a new product) then a little icon or banner appears in the corner of the image.
You need to set up a new Attribute in Catalogue -> Attributes -> Manage Attributes . Set is as a boolean, give it an id of new_product. Make it available on the front end product view (one of the advanced options). Now add the attribute to your custom attribute set if your using one, or the default set if you are not. Go in and set it to ‘Yes’ for your product and save it.

So we’ve got a product in the Magento catalogue which has a boolean flag set to yes for the attribute ‘new_product’. How do we then access that an display it on the front end? Easy.

Magento- Adding Text Inside Subscribe Input Box

Share
Posted on April 17th, 2013 | Posted by admin

A frequent request from customers is to have something like ‘Enter Email Address’ in the subscribe input box. The default subscribe box is just plain white, and empty.
Here is what we are shooting for…

Default Magento default form from subscribe.phtml :
<form action="<?php echo $this->getFormActionUrl() ?>" method="post" id="newsletter-validate-detail">
        <div>
            <div>
                <label for="newsletter"><?php echo $this->__('Sign Up for Our Newsletter:') ?></label>
            </div>
            <div>
              <input type="text" name="email" id="newsletter" value="Email Address" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>
            </div>
            <div>
                <button type="submit" title="<?php echo $this->__('Subscribe') ?>"><span><span><?php echo $this->__('Subscribe') ?></span></span></button>
            </div>

Magento: Modify Collection To Include Comma Separated Values From Another Table

Share
Posted on April 16th, 2013 | Posted by admin

Magento: Modify Collection To Include Comma Separated Values From Another Table
It was rather difficult to come up with a title for this post, so I’m not sure that it is completely accurate. But, I have been working on a module, and I needed to modify the catalog/product collection to add a column that contains comma separated skus of the related products associated to each product.

First step is to get the product collection,

How to set up a Magento store for Australia

Share
Posted on April 15th, 2013 | Posted by admin

Running Magento stores in Australia differs very little from any other country, but there are a few things that you need to do for compliance with ATO requirements and to ensure that Magento calculates taxes correctly. The following is an outline of the necessary configuration and settings you may need to consider when setting up Magento for an Australian store.

First, the basic information for the store must be configured for Australia:

System → Configuration → General
Countries options

  • Default country = Australia
  • Allow countries = ensure Australia is selected

Locale options

Page 1 of 6212345»102030...Last »