Jump to content

Beginner PHP and need some help please, thank you :)


nycforever

Recommended Posts

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);
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Strip-Chez-nous-on-debug-en-prod-650-fin

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Hi all
I 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 option
Goal 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.