nycforever Posted September 13, 2017 Share Posted September 13, 2017 (edited) Hi Beginner with PHP, I am making some changes to an application that was written by someone else. Very little documentation at all, so I'm navigating the code. The portion that I need help with is this - we are currently using a drop down where they choose one option. We need to change it to be checkboxes where they can select as many options as they'd like. I'm sharing the 3 main functions that are related to the task at hand. These functions were spread out over 3 different files, each having 1,000+ lines of code. So I'm a bit overwhelmed to say the least. Thanks so much in advance for your assistance. Will be checking back frequently in case I have left anything out in order to get help. You guys rock! Thank you function rrComponentFields($pre, $component, $loc){ global $locationObj; $dbType = utilities::getDBtype($pre); $outStr = "<select class='input-box' name='{$pre}Conponent' id='{$pre}Conponent' onchange='getConponentDetails(\"$pre\");>"; $gct = $locationObj->getCleanableTargetsByType($pre, $component, $loc); for( $i=0; $i<count($gct); $i++ ){ $row = $gct[$i]; $isSelected = ""; if( $row["SELECTED"] == true ){ $isSelected = "selected=\"selected\""; } $outStr .= "<option value=\"$row[CTID]\" $isSelected> $row[FULLNAME] </option>"; } $outStr .= "</select><input type='checkbox' name='allConponents' value='allConponents' id='{$pre}AllConponents' /> Apply to all conponents <br/>"; return $outStr; } function getConponentDetails(pre){ /*switch(pre){ case "pl": case "i": //url = "getInterlockingInfo.php"; url = "getStationInfoNoConponent.php"; break; case "l": default: url = "getStationInfo.php"; break; } */ var param = document.getElementById( pre+'Conponent' ).value; var eventId = window.eventId; if(window.XMLHttpRequest){ // If IE7, Mozilla, Safari, etc: Use native object var client = new XMLHttpRequest(); }else{ if(window.ActiveXObject){ // ...otherwise, use the ActiveX control for IE5.x and IE6 var client = new ActiveXObject("Microsoft.XMLHTTP"); } } //getEmployees(pre); client.onreadystatechange = function() {conponentDetailhandler(pre, client)}; client.open("GET", "getStationInfo.php" + "?param=" + param + "&eventId=" + eventId); client.send(""); } //getData() function conponentDetailhandler(pre, obj) { console.log( "Pre = ", pre ); var status = document.getElementById(pre+'Status'); var comments = document.getElementById(pre+'History'); var forman = document.getElementById(pre+'Forman'); var pass = document.getElementById(pre+'PassNum'); //var bags = document.getElementById(pre+'NumBags'); var gangButton = document.getElementById('gangEnterUpdate'); var downloadFile = document.getElementById(pre+'DownloadFile'); downloadFile.options.length = 0; if(obj.readyState == 4 && obj.status == 200) { var val = eval('(' + obj.responseText + ')'); for(var i = 0; i < val.length; i++) { var txtNew = document.createElement('text'); txtNew.text = val[i].STATUS; status.value = txtNew.text; txtNew.text = val[i].COMMENTS; comments.value = txtNew.text; txtNew.text = val[i].PASS; if(pass){ pass.value = txtNew.text; } var doctxt = txtNew.text; //------------------------------- //Grab all the attached documents and list in a option txtNew.text = val[i].SUPPORTDOCS; var doctxt = txtNew.text; var docArray = new Array(); if(doctxt && doctxt.length > 0){ docArray = doctxt.split(","); } for(var x = 0; x < docArray.length; x++) { var opt = docArray[x]; var el = document.createElement("option"); el.innerHTML = opt; el.value = opt; downloadFile.appendChild(el); } Edited September 13, 2017 by requinix please use [code] tags when posting code Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 13, 2017 Share Posted September 13, 2017 Thousands of lines in 3 separate files? Have you knowledge of any programming languages? If not, then you risk possibly damaging a working system because what you want to do will require a good bit of changing the HTML code as well as the PHP code that will handle the new inputs from your form. Looking at your code (for only a bit) it could be near impossible for us to provide support what with all the calls to unknown functions/methods that are being used. Are you sure you want to embark upon this task? As a manager I would not ask a novice to go fumbling about in 3000+ lines of code without documentation. Quote Link to comment Share on other sites More sharing options...
dalecosp Posted September 13, 2017 Share Posted September 13, 2017 (edited) Thousands of lines in 3 separate files? Have you knowledge of any programming languages? If not, then you risk possibly damaging a working system because what you want to do will require a good bit of changing the HTML code as well as the PHP code that will handle the new inputs from your form. Looking at your code (for only a bit) it could be near impossible for us to provide support what with all the calls to unknown functions/methods that are being used. Are you sure you want to embark upon this task? As a manager I would not ask a novice to go fumbling about in 3000+ lines of code without documentation. A smart manager would use a sandbox. Perhaps he has one. Edited September 13, 2017 by dalecosp Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 13, 2017 Share Posted September 13, 2017 Testing environments are a given. I stand by my statement - sending a novice into something of this size is waste of time and resources, risky and certainly not a morale boosting exercise. Quote Link to comment Share on other sites More sharing options...
nycforever Posted September 13, 2017 Author Share Posted September 13, 2017 I agree with you 100%. I did speak with him this morning and told him (he hadn't looked at the code) that the files each had from 600-1200+ lines of code each and that me making changes could possibly open a whole can of worms. I am not too proud to say that I don't know and cannot do something, but i'm happy to learn. I told him that I would be happy to sit with a PHP expert who can walk me through the changes and I can take it from there. I did develop 2 basic applications right after I took the PHP classes 2 years ago and those applications, because I used the tools and basics - have been working well as they are both in production and being used by our company Executives (proud moment, more boosting) lol I am thankful for your reply, however, I may need to search a bit more to see if I can at least make an attempt.The chunks of code I provided were from 3 diff files and I provided them because they were called from the initial file, etc. PS there is NO documentation in their files - and there are also NO includes at the tops of the pages-- my understanding was always to have an "include" at the top- but here they have NONE, so if file1.php was calling a function on file2.js, the only way for me to find the function was to search all of the files in directory until I came across the function in file2.js--- very bizarre -- is this the norm with PHP?Thanks again- your honesty is so much appreciated. Quote Link to comment Share on other sites More sharing options...
nycforever Posted September 13, 2017 Author Share Posted September 13, 2017 I forgot to answer your question- yes, I do have experience with css, javascript, jquery, html5, Cold Fusion and basic PHP. I am not a super duper guru in any of them. Quote Link to comment Share on other sites More sharing options...
nycforever Posted September 13, 2017 Author Share Posted September 13, 2017 So the main gist of what i need (and am having difficulty with ) is -- changing the drop down to be a select box which allows use to select as many options as they would like.Thanks so much. Appreciate it. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted September 13, 2017 Share Posted September 13, 2017 Add "multiple" to the HTML select and change the name to include a "[]" at the end. Now the multiple selected options will be passed as an array. Now, the hard part, you need to find everywhere that value is referenced in PHP and make sure the logic deals with an array instead of a singular value. Good luck. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 13, 2017 Share Posted September 13, 2017 I think your main gist has changed. In your original post you said you wanted to switch to checkboxes. Glad to see you have altered your approach since this could be a whole lot easier to handle. Quote Link to comment Share on other sites More sharing options...
nycforever Posted September 13, 2017 Author Share Posted September 13, 2017 Hi allI apologize for any confusion- the main gist is the same - maybe my use of check box and select box cause the confusion. Current scenario: drop down, choose one optionGoal scenario: many options, choose multiple -- using check boxes. If anyone is able to assist with the actual code by showing an example, I would appreciate it.Thanks. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted September 13, 2017 Share Posted September 13, 2017 Generally wouldn't matter to PHP as they come across as arrays, either way. Unless you do something weird with the checkbox naming. Quote Link to comment Share on other sites More sharing options...
nycforever Posted September 13, 2017 Author Share Posted September 13, 2017 Appreciate your feedback. If anyone is able to assist with the actual code by showing an example, I would appreciate it.Thanks. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 13, 2017 Share Posted September 13, 2017 You could use a single select box (dropdown) with the 'multiple' option as suggested already. Quote Link to comment Share on other sites More sharing options...
Sepodati Posted September 13, 2017 Share Posted September 13, 2017 If anyone is able to assist with the actual code by showing an example, I would appreciate it. It's not a simple change this to that, like it is in the HTML. You have to find everywhere the select data is referenced in PHP and update the logic. Maybe even change the database schema if there is one. Even JavaScript, maybe. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.