Entering parent and one or more child records on same page

Topics: User Forum
Feb 14, 2013 at 2:24 PM
Hello, I'm working on an AVFP site in which a user needs to enter (or edit) a single parent/header record along with one or more child/detail records on the same page. I'm struggling a bit with how to best make this happen, since it's a bit more complicated than just entering a single record at a time (which I've already got a good handle on from looking at Claude's examples). Can anyone who has done this give me some guidance?
Feb 14, 2013 at 6:43 PM
Sounds like it should be similar to the new Master-Detail example. Have you looked at that? Just change the display fields to Text boxes and you should be able to take those values and use FoxPro as you normally would to update, append, etc. Once you've got the values it's all regular FoxPro.
Feb 14, 2013 at 7:19 PM
If you're talking about grabbing the entered variables out of a grid that have been submitted as a Form, then yes you may have to get a little tricky. What I've done in the past and is also in the 'Debugging Variable Dump' example is something like:
* Note the use of oRequest.oRequest to get these variables
FOR EACH lcFormVar IN oRequest.oRequest.FORM
    lcVar =   oRequest.oRequest.FORM(lcFormVar).ITEM()
    lcSTR=lcSTR+[    <TR><TD><b> ]+ lcFormVar +[ </b></TD><TD> ] ;
        +lcVar +[</TD></TR>] 
after the user hits the Submit button.
Feb 14, 2013 at 8:03 PM
And here's an example SaveOrder I did a few years back on a complicated order form in a grid like structure:
IF ISNULL(lctable)  &&9/3 CF
   oSession.Value("errormsg","Your session has timed out because of inactivity.  Please login again.")
FOR EACH lcFormVar IN oRequest.oRequest.FORM
  lcVar =   oRequest.oRequest.FORM(lcFormVar).item
  IF lcFormVar <> [keyword] .and. lcFormVar <> [bbb]  .and. ! ISNULL(lcFormVar) .and. ! EMPTY(lcFormvar)  && the search textbox & submit value
    UPDATE &lcTable set amt_next =VAL(lcVar) WHERE cat=lcFormVar
IF oRequest.form("hiddenName")="Save"
Feb 14, 2013 at 9:24 PM
Thanks Claude, from your examples, it looks like I'm on the right track. I've basically created a table with a row for each child record, and made those form fields that can be edited.

How about adding or deleting child records? I'm thinking of adding a checkbox to each row for deleting, but what about adding new rows to the table dynamically?
Feb 14, 2013 at 11:02 PM
Maybe a button or link for 'Add New' and either re-display in the grid with empty text boxes or show a new page like the Detail page in the example for data entry. Then Append the values with regular VFP commands. There are tons of examples for PHP out there that can probably give you more ideas on how to arrange your screen. And anything you can do with PHP you can do with VFP (and probably more).
Feb 15, 2013 at 7:05 PM
Ok, I found an example of how to dynamically add rows to a table with a Javascript:


My problem now is that I need to add dropdown boxes to the table rows instead of just simple text boxes. I'm using the oHTML.htmldropdown() in AVFP to populate those dropdowns, and I'm struggling with how to use that in conjunction with the Javascript example.
Feb 15, 2013 at 7:38 PM
Think I've found a solution. I just call oHTML.htmldropdown(), and store the resulting strings to a couple of hidden input boxes. Then, from within my Javascript, I can use document.getElementById("hiddenfieldname").value to get the string to store for the dynamic dropdown boxes. This seems to work just fine.
Feb 16, 2013 at 2:34 PM
Cool - good work!