- 威望
- 5514
- 開(kāi)源幣
- 293
- 注冊(cè)時(shí)間
- 2007-12-7
- 積分
- 11786
- 帖子
- 3015
- 主題
- 694
- UID
- 52443
| 3、用戶輸入之檢測(cè) 本帖最后由 kakashilw 于 2009-7-2 13:38 編輯
(1)前端
- <script language="JavaScript" type="text/javascript" src="<tpl> $site_url </tpl>/js/jquery/jquery.validate.js"></script>
-
- $(function(){
- $("#ownaddproduct").validate({
- errorClass: "wrong",
- rules: {
- txtPname: {required:true},
- txtPstorage: {
- required:true,
- number:true,
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return 5;
- }else{
- return 1;
- }
- }
- },
- minimumBid: {
- required: "#radioSelltype0:checked",
- number: true,
- min: function(){
- if($("#radioSelltype0").attr('checked')==true){
- return 0.01;
- }else{
- return 0;
- }
- }
- },
- price_step: {
- required: "#radioSelltype0:checked",
- number: true,
- min: function(){
- if($("#radioSelltype0").attr('checked')==true && $("#inc2").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- txtPprice: {required: "#radioSelltype1:checked",number: true,min: 0.01},
- txtGroupprice: {required:"#radioSelltype2:checked",number:true,min: 0.01},
- txtPoldprice: {required: "#radioSelltype2:checked",number: true,min: function(){return $("#txtGroupprice").val();}},
- txtGroupmincount: {
- required: "#radioSelltype2:checked",
- number: true,
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return 5;
- }else{
- return 0;
- }
- },
- max:function(){
- if($("#radioSelltype2").attr('checked')==true){
- if($("#txtPstorage").val() >= 100){
- return 100;
- }else{
- return $("#txtPstorage").val();
- }
- }else{
- return 10000000;
- }
- }
- },
- area_id: {required: true},
- pyTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- kdTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- emsTF: {
- required: "#whopsBuyer:checked",
- number: true,
- min: function(){
- if($("#whopsBuyer").attr('checked')==true){
- return 1;
- }else{
- return 0;
- }
- }
- },
- slValiddays: {
- required: true,
- number: true,
- min: 1,
- max: 30
- }
- },
- messages: {
- txtPname: {required: "<tpl> $errProductNameEmpty </tpl>"},
- txtPstorage: {
- required: "<tpl> $errPstorage </tpl>",
- number: "<tpl> $errPstorage </tpl>",
- min: function(){
- if($("#radioSelltype2").attr('checked')==true){
- return "<tpl> $errPstorageByGroup </tpl>";
- }else{
- return "<tpl> $errPstorage </tpl>";
- }
- }
- },
- minimumBid: {required: "<tpl> $errMinimumbidWrong </tpl>",number: "<tpl> $errMinimumbidWrong </tpl>",min: "<tpl> $errMinimumbidWrong </tpl>"},
- price_step: {required: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>",number: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>",min: "<tpl> $langProductAUserDefinedUppriceIsEmpty </tpl>"},
- txtPprice: {required: "<tpl> $errPprice </tpl>",number: "<tpl> $errPprice </tpl>",min: "<tpl> $errPprice </tpl>"},
- txtGroupprice: {required: "<tpl> $errGroupprice </tpl>",number: "<tpl> $errGroupprice </tpl>",min: "<tpl> $errGroupprice </tpl>"},
- txtPoldprice: {required: "<tpl> $errPoldprice </tpl>",number: "<tpl> $errPoldprice </tpl>",min: "<tpl> $errPoldprice </tpl>"},
- txtGroupmincount: {required: "<tpl> $errGroupmincount </tpl>",number: "<tpl> $errGroupmincount </tpl>",min:"<tpl> $errGroupmincount </tpl>",max:"<tpl> $errGroupmincount </tpl>"},
- area_id: {required:"<tpl> $errProvince </tpl>"},
- pyTF: {required: "<tpl> $langProductPyTFIsEmpty </tpl>",number: "<tpl> $langProductPyTFIsEmpty </tpl>",min: "<tpl> $langProductPyTFIsEmpty </tpl>"},
- kdTF: {required: "<tpl> $langProductKdTFIsEmpty </tpl>",number: "<tpl> $langProductKdTFIsEmpty </tpl>",min: "<tpl> $langProductKdTFIsEmpty </tpl>"},
- emsTF: {required: "<tpl> $langProductEMSTFIsEmpty </tpl>",number: "<tpl> $langProductEMSTFIsEmpty </tpl>",min: "<tpl> $langProductEMSTFIsEmpty </tpl>"},
- slValiddays: {required: "<tpl> $errPSValiddays </tpl>",number: "<tpl> $errPSValiddays </tpl>",min: "<tpl> $errPSValiddays </tpl>",max: "<tpl> $errPSValiddays </tpl>"}
- },
- submitHandler: function() {
- var check_sign = false;//貨幣選擇狀態(tài)標(biāo)識(shí)
- var payment_check = false;//支付方式選擇狀態(tài)標(biāo)識(shí)
- var predeposit_check = false;//預(yù)存款選擇狀態(tài)標(biāo)識(shí)
- var payment_alert_sign = false;//支付方式是否拋出錯(cuò)誤信息標(biāo)識(shí)
-
- //判斷預(yù)存款選擇狀態(tài)
- if($('#pay_predeposit').attr('checked') == true){
- predeposit_check = true;
- }
- //驗(yàn)證支付方式的復(fù)選驗(yàn)證,是否全選,選中的支付方式是否選擇了支付貨幣種類
- $("#ownaddproduct input[@type=hidden]").each(function(){
- if(this.name.indexOf('payment_cur_') == 0){
- //判斷支付方式是否被選擇
- str = this.name.split('payment_cur_');//取支付方式名稱 str[1]
- if($('#txtPayment_'+str[1]).attr('checked') == true){
- //取該支付方式的貨幣種類字符串
- str2 = $('#payment_cur_'+str[1]).val().split('|');
- payment_check = true;//標(biāo)識(shí)有選擇的支付方式
- //判斷該選中的支付方式起碼有一個(gè)支持的貨幣種類被選擇
- for(i=0;i<str2.length;i++){
- if($('#currency_'+str2[i]).attr('checked') == true){
- check_sign = true;
- break;
- }
- }
- if(check_sign == false){//沒(méi)有選擇貨幣
- payment_alert_sign = true;
- }
- }
- }
- check_sign = false;
- });
-
- if(predeposit_check == true){//選擇預(yù)付款
- if(payment_alert_sign == false){//判斷是否有錯(cuò)誤拋出:沒(méi)有
- var oEditor = FCKeditorAPI.GetInstance('txtPinfo');
- $('#txtPinfo').val(oEditor.GetXHTML(true));
- if($('#txtPinfo').val() != ''){
- document.getElementById('ownaddproduct').submit();
- }else{
- alert('<tpl> $errPSInfoEmpty </tpl>');
- return false;
- }
- }else{
- alert('<tpl> $errPaymentSelCur </tpl>');
- return false;
- }
- }else{//沒(méi)有選擇預(yù)存款
- if(payment_alert_sign == false && payment_check == true){//判斷是否有錯(cuò)誤拋出并且選擇了起碼一種支付方式:沒(méi)有
- var oEditor = FCKeditorAPI.GetInstance('txtPinfo');
- $('#txtPinfo').val(oEditor.GetXHTML(true));
- if($('#txtPinfo').val() != ''){
- document.getElementById('ownaddproduct').submit();
- }else{
- alert('<tpl> $errPSInfoEmpty </tpl>');
- return false;
- }
- }else{
- alert('<tpl> $errPaymentSelCur </tpl>');
- return false;
- }
- }
- }
- });
- });
復(fù)制代碼
(2)后端 [php] $this->objvalidate->validateparam = array( array("input"=>$this->_input["txtPname"],"require"=>"true","message"=>$this->_lang['errPSNameEmpty']), array("input"=>$this->_input["slPCId"],"require"=>"true","message"=>$this->_lang['errPcidEmpty']), array("input"=>$this->_input["txtPinfo"],"require"=>"true","message"=>$this->_lang['errPSInfoEmpty']), array("input"=>$this->_input["radioSelltype"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSSelltype']), array("input"=>$this->_input["radioType"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSType']), array("input"=>$this->_input["txtPstorage"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSstorage']), //array("input"=>$this->_input["txtPprice"],"validator"=>"Currency","message"=>$this->_lang['errPSprice']), array("input"=>$this->_input["txtGroupprice"],"validator"=>"Currency","message"=>$this->_lang['errPSGroupprice']), array("input"=>$this->_input["txtPoldprice"],"validator"=>"Currency","message"=>$this->_lang['errPsPoldprice']), array("input"=>$this->_input["txtPoldprice"],"validator"=>"Compare","operator"=>">=","to"=>$this->_input["txtGroupprice"],"message"=>$this->_lang['errPSPriceNoGroupPrice']), array("input"=>$this->_input["txtGroupmincount"],"validator"=>"Number","message"=>$this->_lang['errPSGroupmincount']), array("input"=>$this->_input["area_id"],"require"=>"true","message"=>$this->_lang['errPProductAreaIsEmpty']), array("input"=>$this->_input["radioTransfee"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSTransfee']), array("input"=>$this->_input["radioInvoices"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSInvoices']), array("input"=>$this->_input["radioWarranty"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSWarranty']), array("input"=>$this->_input["slValiddays"],"require"=>"true","validator"=>"Number","message"=>$this->_lang['errPSValiddays']), array("input"=>$this->_input["chxAutopublish"],"validator"=>"Integer","message"=>$this->_lang['errPSAutopublish']), array("input"=>$this->_input["chxRecommended"],"validator"=>"Integer","message"=>$this->_lang['errPSRecommended'])); $error = $this->objvalidate->validate(); if($error != ""){ $this->redirectPath("error","",$error); } [/php] |
|