简体   繁体   English

表单中的值无法解析到MVC框架中的控制器

[英]values from Form not parse over to controller in MVC framework

Task 任务

Am suppose to parse values that I have entered in the respective form field into the controller- action.php. 我想将我在相应表单字段中输入的值解析为controller-action.php。 And have the values reflected in the error log that is in action.php, this is to ensure that the method =POST is posting the correct value from the view to the controller. 并将这些值反映在action.php的错误日志中,以确保method =POST将正确的值从视图发布到控制器。

Issue I was initially able to parse values over, and it was reflected in my error_log. 问题我最初能够解析值,这反映在我的error_log中。 However, for unknown reason, values parsed over now are of the wrong value. 但是,由于未知原因,现在解析的值是错误的值。 It means that if I were to select "Others" and input in my fields, the parse values reflected in the error log is showing details of Agency 3, or if I were ot select "Agency 1", rightfully, values of agency 1 should be post over in the error_log but the values posted are values from agency 3. 这意味着如果我要选择“其他”并在我的字段中输入,错误日志中反映的解析值将显示代理3的详细信息,或者如果我选择“代理1”,则代理1的值应正确在error_log中过帐,但过帐的值是代理商3的值。

I am perplexed as I have tried other field values and it was able to parse over correctly. 我很困惑,因为我尝试了其他字段值,因此能够正确解析。

Can anyone please help me 谁能帮帮我吗

code

Form field in View: 视图中的表单字段:

<form name="form_Agent" id="form_Agent" method="POST" action="action.php" onsubmit="return checkForm(this)">

<li class="bigfield">

                    <select name ="AgencyDetails" id="AgencyDetails" onchange = "return val(this.value);">
                    <option value ="0" selected = "selected"> ..</option>
                    ....
                    </select>
            </li>

<!--: when user select "Others"-->
            <div id = "extradiv" style ="display:none">

                ...
             </div>

             <!--: when user select other options other than "Others"-->
            <div  id = "Agency1" style ="display:none">
           ....</div>

</form>
<!--: Set Conditional check, if user clicks Others, direct to additional input field: Agent Name, Agency Registration Number, Agency Address if click Agency 1 or 2 or 3, to display value-->
<script>
function val(x) {
.....
}

</script>

Error log in Controller: action.php: 错误登录控制器:action.php:

error_log(date("Y-m-d H:i:s")."_-mobile,agencyName: ".$_POST['agencyName']."\n",3,"/var/tmp/value/value.log");
error_log(date("Y-m-d H:i:s")."_-mobile, agencyRegistrationNum: ".$_POST['agentRegistrationNum']."\n",3,"/var/tmp/value/value.log");     

error log result 错误日志结果

2015-09-08 _-mobile: 
2015-09-08 _-mobile: 

It is a simple syntax error that I have overlooked, the 'name' & 'id' are the same for each extra div. 这是我忽略的简单语法错误,每个额外的div的“名称”和“ id”相同。 Hence, html tends to look at the latest tag inputs. 因此,html倾向于查看最新的标签输入。 What I did to solve the following issue is to assign different 'name' and 'id' to each div. 解决以下问题的方法是为每个div分配不同的“名称”和“ id”。 Hence it goes like that: 因此它是这样的:

<div id = "extradiv" style ="display:none">

            <li class="bigfield"><input placeholder="Agency Name" type="text" name="agencyOthersName" id="agencyOthersName"/></li>
        <li class="bigfield"><input placeholder="Agency Registration Num" type="text" name="agentOthersRegistrationNum" id="agentOthersRegistrationNum"/></li>
        <li class="bigfield"><input placeholder="Agency Address" type="text" name="agentOthersAddress" id="agentOthersAddress"/></li>

         </div>

         <!--: when user select other options other than "Others"-->
        <div  id = "Agency1" style ="display:none">
       <li class="bigfield"><input value="Agency Name 1" type="text" name="agency1Name" id="agency1Name"/></li>
        <li class="bigfield"><input value="Agency Registration Num 1" type="text" name="agent1RegistrationNum" id="agent1RegistrationNum"/></li>
        <li class="bigfield"><input value="Agency Address 1" type="text" name="agent1Address" id="agent1Address"/></li>

         </div>

         <div  id = "Agency2" style ="display:none" >
       <li class="bigfield"><input value="Agency Name 2" type="text" name="agency2Name" id="agency2Name"/></li>
        <li class="bigfield"><input value="Agency Registration Num 2" type="text" name="agent2RegistrationNum" id="agent2RegistrationNum"/></li>
        <li class="bigfield"><input value="Agency Address 2" type="text" name="agent2Address" id="agent2Address"/></li></div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM