验证不适用于MVC

时间:2014-12-11 04:51:11

标签: javascript jquery html forms

为什么这段代码不起作用?有人能帮助我吗?

<script type="text/javascript" src="{/literal}{$smarty.const.CONST_SITE_ADDRESS}{literal}js/jquery.validate.min.js"></script>

<script type="text/javascript">

 $(document).ready(function() {    
    $("#form").validate({        
        rules: {
            dish_name  : "required",            
                 price : "required"                
            },            
        messages: {
            dish_name: "Please enter dish name",            
            price: "Please enter price"                                         
            }
    });    
  });      
  </script>

<form enctype="multipart/form-data" method="post" action="?actionvar=Edit" id='form'>
        <section class="field clearfix">     

        <div class="inpt_fields">
                    <div class="first">Dish name<span>*</span></div>
                    <input class="inpt_bx" type="text" id="dish_name" name="dish_name" value="{$actionReturn.data.dish_name}">
        </div>

          <div class="inpt_fields">
                    <div class="first">Select dish Category</div>

                    <select name="category_id" id="category_ids">
                        {foreach from=$actionReturn.categories item=data name=i}
                           {if $data.id==$actionReturn.data.category_id}    
                           <option value="{$data.id}" selected="selected">{$data.category_name}</option>
                           {else}
                            <option value="{$data.id}">{$data.category_name}</option>                           
                           {/if}
                        {/foreach}  
                            <option value="0">Other</option>
                    </select>       

          </div>

          <div class="inpt_fields" id="newcategory">
                    <div class="first">Add new category<span>*</span></div>
                        <input class="inpt_bx" type="text" valtype="emptyCheck-Please enter user name" id="new_category" name="new_category_name">
          </div>

          <div class="inpt_fields">
                    <div class="first">Price<span>*</span></div>
                    <input class="inpt_bx" type="text" id="price" name="price" value="{$actionReturn.data.price}">
          </div>

            <div class="inpt_fields">
                    <div class="first">Image</div>
                    <input class="" type="file" valtype="emptyCheck-Please select image" id="image" name="image" style="">
                    <div><img src="{$actionReturn.data.imagepath}" style="width:150px;height:150px;padding-left:15em;padding-top:2em" alt="No image added"/></div>
            </div>

            <div class="inpt_fields">
                    <div class="first">Select ingredients, if any</div>

                    <div class="inpt_fields">{$actionReturn.ingredients_data}</div>


             </div>                      
            <div class="inpt_fields">
                <div class="first">Add new ingredients, if any</div>
                    <input class="inpt_bx" type="text" id="new_ingredients" name="new_ingredients" value="{$actionReturn.new_ingredients}" placeholder="ingredient1,ingredient2,....">
            </div>


            <div class="inpt_fields snd_bck_btn_feld" align="right">
            <div class="first">&nbsp;</div><a href="manage_dishes.php"><input type="button" style="text-decoration:none;" value="Back" class="back_btn black_button"></a> 
    <input type="submit" valcheck="true" name="actionvar" id="saveDataId" value="Edit" class="rsrvtn_btn2 red_button">
    </div>

  <div class="inpt_fields">
            <div class="first" style="width:auto;padding-bottom:4em">All Fields with <span>*</span> are Mandatory</div></div>
        </section>
        </div>

</form>

1 个答案:

答案 0 :(得分:0)

您可以查看可能对您有所帮助的this SO solution,有一个正在运行的示例。