简体   繁体   中英

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. 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.

Issue I was initially able to parse values over, and it was reflected in my 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.

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:

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. Hence, html tends to look at the latest tag inputs. What I did to solve the following issue is to assign different 'name' and 'id' to each div. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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