Categories > TinyButStrong general >

TBS/PHP newbie

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: schwinck
Date: 2010-08-03
Time: 03:11

TBS/PHP newbie

I use MergeBlock for array containing 4 records of 18 fields.  It correctly repeats 4 sets in the html table form defined between block=begin and block=end.  After user changes data and clicks submit, I need to write all 4 changed records back to the database, but using $_POST I am only seeing the last record.  How do I get the 18 fields back into a 4-record array when the html does not have unique names for the 4 sets of data in the form?  The only examples I can find are simple arrays where the form doesn't repeat the record.
By: Skrol29
Date: 2010-08-03
Time: 09:46

Re: TBS/PHP newbie

Hi Schinck

This is a PHP/HTML problem. The trick is to use array names in the HTML. Then you'll get arrays in $_POST.

For instance:
<input name="id[1]" ...>
<input name="id[2]" ...>
<input name="id[3]" ...>
<input name="id[4]" ...>
Then $_POST['id'] will be an array with 4 items having keys 1,2,3,4.
By: TomH
Date: 2010-08-03
Time: 09:51

Re: TBS/PHP newbie

You'll need to cut and paste your template code so we can see how the form is coded.
By: schwinck
Date: 2010-08-03
Time: 19:59

Re: TBS/PHP newbie

The HTML doesn't have all 4 records defined, because TBS correctly repeats the data on the form table for every record that exists in the array.  I want the record displayed on the form only if it exists in the $Query array.  This will be anywhere from 1 to 4 records.

$Query = array();
$Query = array_slice($programcall->returnparm, 0, $programcall->returncount);                  
$TBS->MergeBlock('b1', 'array', $Query); 

<html>
<body>
<table border="1">
[b1;block=begin]
<tr><td>INSCOVSEQ      [b1.INSCOVSEQ]</td></tr>
<tr><td>INSCODE          [b1.INSCODE]</td></tr>
<tr><td>INSPOLICYID#  [b1.INSPOLICYID#]</td></tr>
<tr><td>INSSUBFNAME    [b1.INSSUBFNAME]</td></tr>
<tr><td>INSSUBLNAME    [b1.INSSUBLNAME]</td></tr>
[b1;block=end]
</table>
</body>
</html>
By: schwinck
Date: 2010-08-03
Time: 20:03

Re: TBS/PHP newbie

I grabbed the wrong form, here is the correct html:

html>
<body>
<h4>Patient: [onshow.patientname]</h4>
<form name="patinsform" method="post" action="PatientInsurance.php">
<table class="form tableData">
[b1;block=begin]
<tr><td class="infoHead" colspan="2">Insurance #[b1.INSCOVSEQ]</td></tr>
<tr><td class="infoLabel">Insurance Company</td><td><input name="inscode" type="text" size="4" value="[b1.INSCODE]"></input>...[b1.INSCOMPANY]</td></tr>
<tr><td class="infoLabel">Effective Date</td><td><input name="inseffdate" type="text" size="10" value="[b1.INSEFFDATE;frm=mm/dd/yyyy]"></input></td></tr>
<tr><td class="infoLabel">Termination Date</td><td><input name="instrmdate" type="text" size="10" value="[b1.INSTRMDATE;frm=mm/dd/yyyy]"></input></td></tr>
<tr><td class="infoLabel">Policy ID#</td><td><input name="inspolicyid#" type="text" size="15" value="[b1.INSPOLICYID#]"></input></td></tr>
<tr><td class="infoLabel">Group ID#</td><td><input name="insgrp#" type="text" size="12" value="[b1.INSGRP#]"></input></td></tr>
<tr><td class="infoLabel">Copayment</td><td><input name="inscopay" type="test" size="7" value="[b1.INSCOPAY;frm='0,000.00']"></input></td></tr>
<tr><td class="infoLabel">Subscriber First Name</td><td><input name="inssubfname" type="text" size="15" value="[b1.INSSUBFNAME]"></input></td></tr>
<tr><td class="infoLabel">Subscriber Last Name</td><td><input name="inssublname" type="text" size="15" value="[b1.INSSUBLNAME]"></input></td></tr>
<tr><td class="infoLabel">Subscriber Address</td><td><input name="inssubaddr1" type="text" size="28" value="[b1.INSSUBADDR1]"></input></td></tr>
<tr><td class="infoLabel">Subscriber Address</td><td><input name="inssubaddr2" type="test" size="28" value="[b1.INSSUBADDR2]"></input></td></tr>
<tr><td class="infoLabel">Subscriber City</td><td><input name="inssubcity" type="text" size="15" value="[b1.INSSUBCITY]"></input></td></tr>
<tr><td class="infoLabel">Subscriber State</td><td><input name="inssubstate" type="text" size="2" value="[b1.INSSUBSTATE]"></input></td></tr>
<tr><td class="infoLabel">Subscriber Zip Code</td><td><input name="inssubzipcode" type="text" size="9" value="[b1.INSSUBZIPCODE]"></input></td></tr>
<tr><td class="infoLabel">Relationship to Patient</td><td><input name="inssubrel" type="text" size="1" value="[b1.INSSUBREL]"></input></td></tr>
<tr><td class="infoLabel">Gender</td><td><input name="inssubsex" type="text" size="1" value="[b1.INSSUBSEX]"></input></td></tr>
<tr><td class="infoLabel">Birthdate</td><td><input name="inssubbirdate" type="text" size="10" value="[b1.INSSUBBIRDATE;frm=mm/dd/yyyy]"></input></td></tr>
<tr><td class="infoLabel">Telephone</td><td><input name="inssubphone#" type="text" size="10" value="[b1.INSSUBPHONE#]"></input></td></tr>
<tr><td class="infoLabel">Employer</td><td><input name="inssubemplyer" type="text" size="30" value="[b1.INSSUBEMPLYER]"></input></td></tr>
[b1;block=end]
</table>
<p><input type="submit" name="update" value="Update"/></p>
</form>
</body>
</html>
By: TomH
Date: 2010-08-03
Time: 20:53

Re: TBS/PHP newbie

As you saw above, Skrol29 gave the proper answer - using the array brackets is recognized by PHP.

I would only add - if you have a variable number of records - that you can use TBS native row number to generalize Skrol29's answer like this
<input name="inscode[[b1.#]]" type="text" size="4" value="[b1.INSCODE]"></input>...[b1.INSCOMPANY]

Hmmm... that is tested ;)... the bracket inside a bracket does actually work for me.