关于前台提交数据保存案例

(1)前台经过 from 表单提交,到数据保存简单案例,可实现前台验证!

   以下是前台代码:

               <form οnsubmit="return fun9()" action="" method="post" name="form1" id="form1">
 @*                @Html.HiddenFor(m =>Model.FId)
                 <input type="hidden" value="@Model.FId" id="FID" name="FID"/>*@
                <table width="100%" height="520" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                        <td align="right">
                        </td>
                        <td colspan="3" align="left" style="color: Red;">
                            @*=========信息结束==========*@
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 200px">
                            <span class="register_mid_font_red">*</span>企 业 名 称 :
                        </td>
                        <td>
                            <input type="text" value="" name="FName" id="FName" οnblur="fun4();" style="font-family: Verdana,Arial;
                                font-size: 10pt;" class="wd2" />
                        </td>
                        <td width="55%" class="grey_font_style">
                            <span id="uname">(企业名称只能输入中 文、英文、数字组成)</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <span class="register_mid_font_red">*</span>机构代码证号:
                        </td>
                        <td>
                            <input type="text" value="" name="FDepNo" id="FDepNo" οnblur="fun7();" style="font-family: Verdana,Arial;
                                font-size: 10pt;" class="wd2" />
                        </td>
                        <td width="55%" class="grey_font_style">
                            <span id="pno">(请如实填写,该号码将是 您所代表的企业的农事无忧号的一部分)</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <span class="register_mid_font_red">*</span>密 码:
                        </td>
                        <td>
                            <input type="password" value="" name="FPassWord" id="FPassWord" οnblur="fun5();"
                                style="font-family: Verdana,Arial; font-size: 10pt;" class="wd2" />
                        </td>
                        <td class="grey_font_style">
                            <span id="pwd">(密码最少不能少于6个字 符)</span>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <span class="register_mid_font_red">*</span>确 认 密 码 :
                        </td>
                        <td>
                            <input type="password" value="" name="ConfirmPassword" id="ConfirmPassword" οnblur="fun6();"
                                style="font-family: Verdana,Arial; font-size: 10pt;" class="wd2" />
                        </td>
                        <td class="grey_font_style">
                            <span id="pwd2">(两次密码必须输入一致 )</span>
                        </td>
                    </tr>
                    <!--验证码-->
                    <tr>
                        <td height="61" align="right">
                            <span class="register_mid_font_red">*</span>验 证 码 :
                        </td>
                        <td>
                            @Html.TextBoxFor(m => Model.FVerifyImg,new { @class = "register_input_bg1", @maxlength = "4" })
                            &nbsp;&nbsp;
                            <img src="@Url.Action("VirifyImg")" id="verify_code"  alt="看不清?点击换一个" οnclick="this.src=this.src+'?'" style="cursor:pointer;" />
                            @Html.ValidationMessageFor(m =>Model.FVerifyImg)
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td height="45">
                            &nbsp;
                        </td>
                        <td colspan="2">
                            <table width="100%" height="38" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td width="4%">
                                        <input type="checkbox" name="checkbox" id="checkbox_xy" checked="checked" />
                                        <label for="checkbox">
                                        </label>
                                    </td>
                                    <td width="96%">
                                        <span class="grey_font_style">
                                            <label for="checkbox">
                                                阅读 <a href="UserGreement" target="_blank">《 农事无忧企业服务协议 》 </a>
                                            </label>
                                        </span>
                                        <label for="checkbox">
                                        </label>
                                    </td>
                                </tr>
                                <!--注册按钮-->
                                <tr>
                                    <td height="84" colspan="3" align="left">
                                        <input type="submit" id="submit" value="  提交申请  " class="zhuce " />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span
                                            style="color: Red; font-size: larger">@ViewBag.ErrorMsgc</span>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td height="123">
                            &nbsp;
                        </td>
                        <td colspan="2" valign="middle">
                        </td>
                    </tr>
                </table>
                </form>

(2)【asp.netMVC4处理】后台相应相关代码:

 

      //-------------------------------Begin*****网商申请页面*****Begin-----------------------------------------------//
        #region 网商申请页面 + WTH
        [HttpPost]
        public ActionResult AppBusinessRep(UserInfo model, string FID, UserCompany model2, UserPersonal model3, string FDepNo = "", string FName = "")
        {
            //  ViewData["user_name"] = user_name;     , string user_name = "", string  user_id = "", string token = ""
            //  ViewData["user_id"] = user_id;
            //  ViewData["token"] = token;
            ViewData["FDepNo"] = FDepNo;
            ViewData["FName"] = FName;
            if (Session["checkcode"] != null && model.FVerifyImg.Trim() == Session["checkcode"].ToString())
            {
                UserInfoBLL userinfobll = new UserInfoBLL();
                UserCompanyBLL usercompanybll = new UserCompanyBLL();
                UserInfo userinfo = userinfobll.FindALL().Where<UserInfo>(s => s.FName == model.FName.Trim()).FirstOrDefault();
                // UserCompany usercompany = usercompanybll.FindALL ().Where<UserCompany>(s => s.FId == model2.FId.Trim()).FirstOrDefault();
                UserCompany usercompany = usercompanybll.FindALL().Where<UserCompany>(s => s.FName == model2.FName.Trim()).FirstOrDefault();//检查是否在数据库中存在
                if (userinfo == null && usercompany == null)  // && usercompany == null
                {

                    model.FId = TableUtils.SetFID();
                    model.FPassWord = EncryptUtil.MD5String(model.FPassWord.Trim()).Trim(); //对密码进行加密
                    // model.FPassWord = model.FPassWord;
                    //  model.FNoWorryId = DateTime.Now.Year.ToString() +  DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +  DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() +  DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString();
                    UserInfoController uc = new UserInfoController();
                    //  string DT = uc.getNextNum();
                    //  model.FNoWorryId = model.FDepNo + uc.getNextNum();         //      uc.Page_Load();    //uc.getNextNum();// SequenceManager.GenNo("组织机构代码证号", 3) 可以获取三位序列号
                    model.FNoWorryId = model.FDepNo + SequenceManager.GenNo("model.FDepNo", 3);
                    model2.FName = model.FNoWorryId;   //把新生成的机构代码号+000 ---->  FName
                    model.FCreatorId = "-1";//自注册用户
                    model.FIsDelete = false;//表示未被删除
                    model.FCreateTime = DateTime.Now;
                    model.FUpdatorId = "-1";//自注册用户
                    model.FUpdateTime = DateTime.Now;
                    model.FInfoIsFinished = "0";//0资料未完善,1资料完善未审核,2审核通 过,3审核未通过
                    model.FUserTypeId = UserTypeEnum.Admin;
                    model.FIsAdmin = 0;
                    model2.FId = model.FId;
                    model.FAgentState = 1;
                    model.FState = 2;  //***************************** 0 --- > 2

                  //  model.FState = model3.FState; //建立UserInfo表和UserPersonal表的 FState 关联
                    model2.FCreatorId = CurrentUser.FId;
                    model2.FBusinessID = CurrentUser.FId;
                    string name = model.FName;  //换名字
                    model.FName = model2.FName;
                    model2.FName = name;


                    if (userinfobll.Create(model))
                    {
                        ////************添加代码*************

                        //if (model != null)
                        //{
                        //    userinfobll.Create(model);
                        //    Session["TypeFName"] = FName;

                        //    UserInfo _modelnew = bll.Fetch(FID);
                        //    _modelnew.FAgentState = 1;//标示提交网商代表审核中 .......
                        //    userinfobll.Edit(_modelnew);  // 进行编辑操作

                        //    bool result = usercompanybll.Create(model2);
                        //}

                        ////************添加代码*************
                        Session["TypeFName"] = FName;
                        bool result = usercompanybll.Create(model2);

                    }
                    Session["Userid2"] = model.FId;
                    return RedirectToAction("BusinessSuccess/" + model.FNoWorryId + "");
                }
                else
                {
                    ////ViewBag.ErrorMsg = "该用户已存在!";
                    ////   ViewBag.ErrorMsg2 = "该用户已存在!";
                    //UserInfo userc = userinfobll.FindALL().Where(x => x.FName ==  model.FName).FirstOrDefault();
                    //if (userc != null)
                    //{
                    ViewBag.ErrorMsgc = "该企业名称已被申请使用!请更换企业名称!";
                    //}
                    return View();
                }
            }
            else
            {
                ViewBag.ErrorMsg = "验证码不正确!";
                return View(model);
            }
        }
        #endregion





        //-------------------------------END******网商申请页面*******END-----------------------------------------------//

另加一个Get提交:如下:

        [HttpGet]
        public ActionResult AppBusinessRep() {

            return View();
        }

 

注意:前台追加验证相关js代码:如下

    <script type="text/javascript">
        $(function () {
            $("form").submit(function () {
                if ($("#checkbox_xy").attr("checked") == null) {
                    alert("请先阅读并接受服务条款!");
                    return false;
                }
            });
        }); 
    </script>
    <script src="/js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <meta name="viewport" content="width=device-width" />
    <script type="text/javascript">

        function fun4() {
            var FName = document.getElementById("FName").value;
            var reg = /[\w\u4e00-\u9fa5]/
            if (reg.test(FName) == false) {
                document.getElementById("uname").className = "zt";
            } else {
                document.getElementById("uname").className = "zt1";
            }
        }
        function fun5() {
            var FName = document.getElementById("FPassWord").value;
            if (FName.length < 6) {
                document.getElementById("pwd").className = "zt";
            } else {
                document.getElementById("pwd").className = "zt1";
            }
        }
        function fun6() {
            var FName = document.getElementById("FPassWord").value;
            var FName1 = document.getElementById("ConfirmPassword").value;
            if (FName != FName1) {
                document.getElementById("pwd2").className = "zt";
            } else {
                document.getElementById("pwd2").className = "zt1";
            }
        }
        function fun7() {
            var FDepNo = document.getElementById("FDepNo").value;
            var reg1 = /^(\w){6,20}$/
            if (reg1.test(FDepNo) == false) {
                document.getElementById("pno").className = "zt";
            } else {
                document.getElementById("pno").className = "zt1";
            }
        }
        function fun9() {
            var FName = document.getElementById("FName").value;
            var reg = /[\w\u4e00-\u9fa5]/
            var FDepNo = document.getElementById("FDepNo").value;
            var reg1 = /^(\w){6,20}$/    //由英文和数字组成
            if (reg.test(FName) == false) {
                document.getElementById("FName").focus();
                return false;
            }
            document.getElementById("uname").className = "zt1";


            var FName1 = document.getElementById("FPassWord").value;
            if (FName1.length < 6) {
                document.getElementById("FPassWord").focus();
                return false;
            }
            document.getElementById("pwd").className = "zt1";

            var FName2 = document.getElementById("FPassWord").value;
            var FName3 = document.getElementById("ConfirmPassword").value;
            if (FName2 != FName3) {
                document.getElementById("ConfirmPassword").focus();
                return false;
            }
            document.getElementById("pwd2").className = "zt1";
            if (reg1.test(FDepNo) == false) {
                document.getElementById("FDepNo").focus();
                return false;
            }
            document.getElementById("pno").className = "zt1";

            return true;

        }
    </script>

 

转载于:https://www.cnblogs.com/softmans/p/3302546.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值