PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Oct 14, 2019 9:22 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Mar 28, 2018 5:49 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Hi,

Over two years ago I created some test php code to see if I could figure out how to have (a series of input text boxes in a table which is on a form) that the user could selectively update then once they were done they would click the submit button and the same php page would process them in a loop to do some updates to the file. An extract of the test code I used to see if I could get it to work is below (I stripped out the style command to make it easier to read). Because I didn't have the need at the time I didn't fully complete the code.

Now I have the need to get it working but I just realized I need to bring in the $fldMM_Key from the table via the same table loop so I know what record to update on the file. However there is no need for the user to update this data. I am assuming I have to put the $fldMM_Key in a "input textbox" as shown in the example immediately below so I can use the command $fldMM_Key = $_POST['fooMasterKey'][$RowCnt]; to capture the key. I would have to protect the text box of course but I am pretty sure I can figure out how to do that. Am I correct in thinking I can only bring in table column data from input fields or is there a way to bring in a column of table data in a loop without having to put it in a textbox? If so are there some examples kicking around? If not how might I create a google search to find them? "PHP capture table column data without an input keyword" maybe? Or maybe the trick I use "PHP = $_POST[' '][$ ]; loop" where I remove anything specific to my app would work to pull up examples and they may show what I am looking for.

Thanks,
John

Notice I have used the prefix "foo" which came from the example I learned this from. I still use ti to indicate to myself the data is from table input.

Syntax: [ Download ] [ Hide ]
echo("<td><input type='textbox' name='fooMasterKey[]' value='$fldMM_Key' size='7''></td>\n");

$fldMM_Key = $_POST['fooMasterKey'][$RowCnt];

 



test PHP code that is in a loop and use to create the the table of input text boxes.
Syntax: [ Download ] [ Hide ]
  echo("<td>$fldMM_Key</td>\n");
  echo("<td>$fldMM_FirstName</td>\n");
  echo("<td>$fldMM_MiddleName</td>\n");
  echo("<td>$fldMM_LastName</td>\n");
  $SoundLevel1of3 = $RowCnt;
  echo("<td><input type='textbox' name='foo1of3[]' value='$SoundLevel1of3' size='7' onchange='funcEditValue(this.value)'></td>\n");
  $SoundLevel2of3 = $RowCnt + 1;
  echo("<td><input type='textbox' name='foo2of3[]' value='$SoundLevel2of3' size='7' onchange='funcEditValue(this.value)'></td>\n");
  $SoundLevel3of3 = $RowCnt + 2;
  echo("<td><input type='textbox' name='foo3of3[]' value='$SoundLevel3of3' size='7' onchange='funcEditValue(this.value)'></td>\n");
 


test PHP code that is in a loop to bring in the table input text boxes.
Syntax: [ Download ] [ Hide ]
if (isset($_POST['ProcessTextBoxes'])) {
   $RowCnt=0;
   //START: NOT FINISHED In here you need to place the same query that loads the table which shows on the form
   //       Currently only the fldMM_FirstName and other fields shown below are being loaded on the table.
   //       You never bothered to put the three SoundPot values in that file.
   //       You just wanted to find out if you could pick up all these values.
   //END: NOT FINISHED In here you need to place the same query that loads the table
   while($row = mysqli_fetch_array($result)) {
     $fldKRP_Key =  $row['fldKRP_Key'];
     $fldKRP_Member_LU = $row['fldKRP_Member_LU'];
     $fldMM_FirstName = $row['fldMM_FirstName'];
     $fldMM_MiddleName = $row['fldMM_MiddleName'];
     $fldMM_LastName = $row['fldMM_LastName'];
     $fldKRP_InstrumentRecKey =  $row['fldKRP_InstrumentRecKey'];
     $fldIF_Name =  $row['fldIF_Name'];
     $SoundPot1of3 = $_POST['foo1of3'][$RowCnt]; //These commands get the data updates from the table
     $SoundPot2of3 = $_POST['foo2of3'][$RowCnt];
     $SoundPot3of3 = $_POST['foo3of3'][$RowCnt];
     $RowCnt=$RowCnt + 1;
   }
}


Top
 Profile  
 
PostPosted: Wed Mar 28, 2018 8:37 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Interesting. This search
Syntax: [ Download ] [ Hide ]
<td> name='[]' </td>


Led me to this example.
Syntax: [ Download ] [ Hide ]
<table>
  <tr>
    <th id="name">Name</th>
    <th id="email">Email</th>
    <th id="phone">Phone</th>
    <th id="addr">Address</th>
  </tr>
  <tr>
    <td headers="name">John Doe</td>
    <td headers="email">someone@example.com</td>
    <td headers="phone">+45342323</td>
    <td headers="addr">Rosevn 56,4300 Sandnes,Norway</td>
  </tr>
</table>


Which makes me think the php code might be able to loop through the header name without needing an input. However this search loop is finding nothing "php retrieve html table header names _POST loop"

I guess I will just go ahead and put the master key in an input field and protect it with readonly and disabled as below. I just tested these two keywords and it works.

Syntax: [ Download ] [ Hide ]
echo("<td><input type='textbox' name='fooMelody[]' value='$ParticipateMelody' size='1' readonly disabled onclick='funcInsertM(this.value,$CurrRow)'></td>\n");


Top
 Profile  
 
PostPosted: Wed Mar 28, 2018 11:38 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
What don't you just use a hidden form field?

<input type="hidden" ...>

_________________
(#10850)


Top
 Profile  
 
PostPosted: Thu Mar 29, 2018 3:32 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 179
Hi Christopher,

you mean hide the master key rather than protect it. Yes I could do that actually. The user does not need to see it now. I have never done that with a table column. I should give it a try. It would also free up some space on the page. Thanks for the idea.

John


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group