DEV Community

Discussion on: Beginner Node Help- take 2

Collapse
 
dmfay profile image
Dian Fay

When a form posts back, it only sends the values of named inputs (and selects and textareas etc). Everything else, including your table, is just static content. So if you want the course to be available in the update route, you need an input to hold that information. You can use the "hidden" input type to ensure the user doesn't have to see it.

I'm not really following what you're trying to say with the second issue. Remember your HTML table doesn't exist as far as the update route is concerned: it only cares about what's in those inputs, and those get parted out to fields in req.body automatically. Your SQL statement looks correct at a glance, although with NC is new to me -- wait, is this DB2 syntax?!

Thread Thread
 
masmithrpg profile image
masmithrpg

Yes, this is DB2 systax. NC is No Commit. It is used when the database is not journaled.

I have been chasing down processing the req.body all day without luck.

to explain what i meant with my second issue, take a look at the following. I have entered 1 golfer and his score

INSERT INTO TSTMIS.SCORECARD (COURSE,GOLFER, GDATE, HOLE1,HOLE2,HOLE3,HOLE4, HOLE5, HOLE6, HOLE7, HOLE8, HOLE9, HOLE10, HOLE11, HOLE12, HOLE13, HOLE14, HOLE15, HOLE16, HOLE17, HOLE18)
       VALUES ('Highland,Highland,Highland,Highland,Highland,Highland','mike smith,,,,,',CURRENT_DATE, 4,,,,,, 4,,,,,, 4,,,,,,4,,,,,, 4,,,,,, 4,,,,,,
       4,,,,,, 4,,,,,, 4,,,,,,4,,,,,, 4,,,,,, 4,,,,,,4,,,,,, 4,,,,,, 4,,,,,,
       4,,,,,, 4,,,,,, 4,,,,, ) with NC

I do see a clearer picture when i output req.body to the console, however, i cannot figure out how to process it . Apparently i cannot iterate through it, which means i need to do something with it so that i can iterate.
just a snipped of the req.body

{ id: 'Highland Park' }
Highland Park
{ save: 'Submit',
  GOLFER: [ 'mike smith', '', '', '', '', '' ],
  PAR1: [ '', '', '', '', '', '' ],
  PAR2: [ '', '', '', '', '', '' ],
  PAR3: [ '', '', '', '', '', '' ],
Thread Thread
 
dmfay profile image
Dian Fay

req.body is a hash, not an array. You can't iterate it, but you shouldn't need to. If you want the scores for the fifth hole, for example, that's req.body.PAR5 based on how you've named your input elements. That is an array since you have multiple inputs named PAR5, so Mike's score should be req.body.PAR5[0].

Thread Thread
 
masmithrpg profile image
masmithrpg

I was close.

The example i came across,showed req.body[0].PAR5

thanks for the help.

Thread Thread
 
masmithrpg profile image
masmithrpg

Unfortunately, i don't find much time to work on this, but today i got back to it and found a problem. I don't know if it is an issue i have to deal with because of HTML or because of body.parser.
I have a golf course named 'Highland Park'
i pass the course in as result in my .pug file and it displays properly.
I then have a hidden field in my body for the course name

td: b <input type="hidden" name = "COURSE" value= #{result}
when i process my hash, course shows as 'Highland'
it doesn't appear to be a size issue, but something to do with the space.

If i change the course name to 'HighlandPark', my hash shows 'HighlandPark'

Hope that makes sense.

Any idea how to handle this?