3

I have this form where validation for upload file works but validation for dropdown isn't working.

    <form name="designer-upload" class="designer-uploads form-group" id="designer-upload" action="<?php echo Mage::getUrl('designerr/account/upload/'); ?>" method="post" enctype="multipart/form-data">

        <ul class="form-list">
            <li class="fields">
                <?php $_helper = Mage::helper('catalog/category') ?>
                <?php $_categories = $_helper->getStoreCategories() ?>
                <?php $currentCategory = Mage::registry('current_category') ?>
                <?php if (count($_categories) > 0): ?>
                    <div class="fieldset">
                        <label  class="bold-text"><?php echo $this->__('Category') ?></label>
                        <select class="input-text required-entry" name="drp_category" id="drp_category" >
                            <option><?php echo $this->__('Please Select') ?></option>
                            <?php
                            foreach ($_categories as $parent) {
                                echo '<option value="' . $parent->getId() . '">' . ucfirst($parent->getName()) . '</option>';
                            }
                            ?>
                        </select>
                    </div>
                <?php endif; ?>

                <div class="fieldset">
                    <label  class="bold-text"><?php echo $this->__('Subcategory') ?></label>
                    <select class="input-text required-entry" name="drp_subcategory" id="drp_subcategory" >
                        <option><?php echo $this->__('Please Select'); ?></option>

                    </select>
                </div>

            </li>
            <li class="wide">
                <div class="fieldset">
                    <label for="attachment" class="bold-text"><?php echo $this->__('attachment') ?></label>

                    <input name="MAX_FILE_SIZE" type="hidden" value="2000000"  />
                    <input name="attachment" id="attachment" class="input-text required-entry " type="file" />
                </div>
            </li>
        </ul>
        <div class="buttons-set">
            <input type="submit" name="submit" value="<?php echo $this->__('Submit') ?>" class="button" />
        </div>

    </form>

  <script type="text/javascript">
            //< ![CDATA[
            var customForm = new VarienForm('designer-upload', true);
            //]]>
        </script>

2 Answers 2

5

you have to add null or empty value to select for validation work.

when you add html like this

<option><?php echo $this->__('Please Select') ?></option>

this <?php echo $this->__('Please Select') ?> become value too. like this

<option value="<?php echo $this->__('Please Select') ?>"><?php echo $this->__('Please Select') ?></option>

so add it like

<option value=""><?php echo $this->__('Please Select') ?></option>

<?php if (count($_categories) > 0): ?>
                    <div class="fieldset">
                        <label  class="bold-text"><?php echo $this->__('Category') ?></label>
                        <select class="input-text required-entry" name="drp_category" id="drp_category" >
                            <option value=""><?php echo $this->__('Please Select') ?></option>
                            <?php
                            foreach ($_categories as $parent) {
                                echo '<option value="' . $parent->getId() . '">' . ucfirst($parent->getName()) . '</option>';
                            }
                            ?>
                        </select>
                    </div>
                <?php endif; ?>
0

Replace your code to bellow code

<form name="designer-upload" class="designer-uploads form-group" id="designer-upload" action="<?php echo Mage::getUrl('designerr/account/upload/'); ?>" method="post" enctype="multipart/form-data">

        <ul class="form-list">
            <li class="fields">
                <?php $_helper = Mage::helper('catalog/category') ?>
                <?php $_categories = $_helper->getStoreCategories() ?>
                <?php $currentCategory = Mage::registry('current_category') ?>
                <?php if (count($_categories) > 0): ?>
                    <div class="fieldset">
                        <label for="category" class="bold-text"><?php echo $this->__('Category') ?><span class="required">*</span></label>
                        <select class="required-entry select" name="drp_category" id="drp_category" >
                            <option value=""><?php echo $this->__('Please Select') ?></option>
                            <?php
                            foreach ($_categories as $parent) {
                                echo '<option value="' . $parent->getId() . '">' . ucfirst($parent->getName()) . '</option>';
                            }
                            ?>
                        </select>
                    </div>
                <?php endif; ?>

                <div class="fieldset">
                    <label for="subcategory" class="bold-text"><?php echo $this->__('Subcategory') ?><span class="required">*</span></label>
                    <select class="required-entry select" name="drp_subcategory" id="drp_subcategory" >
                        <option value=""><?php echo $this->__('Please Select') ?></option>
                     </select>
                </div>

            </li>
            <li class="wide">
                <div class="fieldset">

                    <label for="attachment" class="bold-text"><?php echo $this->__('attachment') ?><span class="required">*</span></label>
                    <input name="MAX_FILE_SIZE" type="hidden" value="2000000"  />
                    <input name="attachment" id="attachment" class="input-text required-entry " type="file" />
                </div>
            </li>
        </ul>
        <div class="buttons-set">
            <input type="submit" name="submit" value="<?php echo $this->__('Submit') ?>" class="button" />
        </div>

    </form>

  <script type="text/javascript">
            //< ![CDATA[
            var customForm = new VarienForm('designer-upload', true);
            //]]>
        </script>

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.