0

On the Magento shopping cart, there is always a default form for estimating your shipping cost on the shopping cart page, and these fields are always required,

Country
State/Province
Poscode

How can I simplify this form by requiring Country input only?

This is the Estimate Shipping code form list,

<ul class="form-list">
                <li>
                    <label for="country" class="required"><?php echo $this->__('Country') ?><em>*</em></label>
                    <div class="box-input">
                        <?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
                    </div>
                </li>
            <?php if($this->getStateActive()): ?>
                <li>
                    <label for="region_id"<?php if ($this->isStateProvinceRequired()) echo ' class="required"' ?>><?php if ($this->isStateProvinceRequired()) echo '<em>*</em>' ?><?php echo $this->__('State/Province') ?></label>
                    <div class="box-input">
                        <select id="region_id" name="region_id" title="<?php echo $this->__('State/Province') ?>" style="display:none;"<?php echo ($this->isStateProvinceRequired() ? ' class="validate-select"' : '') ?>>
                            <option value=""><?php echo $this->__('Please select region, state or province') ?></option>
                        </select>
                       <script type="text/javascript">
                       //<![CDATA[
                           $('region_id').setAttribute('defaultValue',  "<?php echo $this->getEstimateRegionId() ?>");
                       //]]>
                       </script>
                       <input type="text" id="region" name="region" value="<?php echo $this->escapeHtml($this->getEstimateRegion()) ?>"  title="<?php echo $this->__('State/Province') ?>" class="input-text" style="display:none;" />
                   </div>
                </li>
            <?php endif; ?>
            <?php if($this->getCityActive()): ?>
                <li>
                    <label for="city"<?php if ($this->isCityRequired()) echo ' class="required"' ?>><?php if ($this->isCityRequired()) echo '<em>*</em>' ?><?php echo $this->__('City') ?></label>
                    <div class="box-input">
                        <input class="input-text<?php if ($this->isCityRequired()):?> required-entry<?php endif;?>" id="city" type="text" name="estimate_city" value="<?php echo $this->escapeHtml($this->getEstimateCity()) ?>" />
                    </div>
                </li>
            <?php endif; ?>
                <li>
                    <label for="postcode"<?php if ($this->isZipCodeRequired()) echo ' class="required"' ?>><?php if ($this->isZipCodeRequired()) echo '<em>*</em>' ?><?php echo $this->__('Zip/Postal Code') ?></label>
                    <div class="box-input">
                        <input class="input-text validate-postcode<?php if ($this->isZipCodeRequired()):?> required-entry<?php endif;?>" type="text" id="postcode" name="estimate_postcode" value="<?php echo $this->escapeHtml($this->getEstimatePostcode()) ?>" />    
                    </div>
                </li>
            </ul>

if I remove the fields of State/Province and Poscode manually, this form will not be working.

Any idea what I can do so there is only Country field is required?

But I need State/Province and Poscode to be required on my Checkout page though...

1

You don't say here why the form doesnt work. I suspect its because you havent changed the javascript at the bottom to remove all the references to zipcode.

If still having problems then suggest set a breakpoint and debug this in the browser.

To debug in Chrome a simple method is right click and select Inspect element. Then you will see any errors that are thrown and can work from there.

Adding the line 'debugger;' in the javascript will help you step thro those issues.

In theory its possible to make this form just use country, as long as the underlying carrier supports this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.