Jump to content


Photo

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


  • Please log in to reply
13 replies to this topic

#1 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 12:58 PM

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 by requinix, 13 September 2017 - 01:32 PM.
please use [code] tags when posting code


#2 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 3,928 posts
  • LocationVoorheesville NY

Posted 13 September 2017 - 01:34 PM

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.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#3 dalecosp

dalecosp
  • Members
  • PipPipPip
  • Advanced Member
  • 396 posts
  • LocationMissouri

Posted 13 September 2017 - 01:46 PM

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


Edited by dalecosp, 13 September 2017 - 01:50 PM.

"God doesn't play dice" --- Albert Einstein
"Perl is hardly a paragon of beautiful syntax." --- Weedpacket

#4 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 3,928 posts
  • LocationVoorheesville NY

Posted 13 September 2017 - 02:02 PM

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.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#5 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 03:06 PM

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.



#6 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 03:08 PM

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



#7 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 04:12 PM

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.



#8 Sepodati

Sepodati
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts
  • LocationCaro, MI

Posted 13 September 2017 - 04:31 PM

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.

#9 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 3,928 posts
  • LocationVoorheesville NY

Posted 13 September 2017 - 04:35 PM

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.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#10 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 05:12 PM

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.



#11 Sepodati

Sepodati
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts
  • LocationCaro, MI

Posted 13 September 2017 - 05:14 PM

Generally wouldn't matter to PHP as they come across as arrays, either way. Unless you do something weird with the checkbox naming.

#12 nycforever

nycforever
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 September 2017 - 06:07 PM

Appreciate your feedback.

 

If anyone is able to assist with the actual code by showing an example, I would appreciate it.

Thanks.



#13 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 3,928 posts
  • LocationVoorheesville NY

Posted 13 September 2017 - 08:07 PM

You could use a single select box (dropdown) with the 'multiple' option as suggested already.


JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#14 Sepodati

Sepodati
  • Members
  • PipPipPip
  • Advanced Member
  • 183 posts
  • LocationCaro, MI

Posted 13 September 2017 - 08:38 PM

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.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users