Response from Web form won't display anything after a space on the console

Viewed 54

I've run into another issue and was hoping someone can help me figure it out. I've managed to pull information from a form and store it in a database. But I noticed that when I display the data onto the console parts of the information are left behind when there is a space in between. For example, the value for the options element for room can be "learning web development". When I try to display that into the console it only gives me "Learning". What is weird is that all of the words including spaces in between are added into the database.

 <form class="form-container"  method="POST">

            <div class="form-group">
                <label>Room</label>
                <select name="room" class="form-select" required aria-label="select example">
                {{#each room}}
                <option class="rooms" value={{this.room}}>{{this.room}}</option>
                {{/each}}
                </select>
                <label>Session</label>
                <select name="session" class="form-select" required aria-label="select example">
                {{#each room}}
                    <option class="rooms" value={{this.session_name}}>{{this.session_name}}</option>
                {{/each}}
                </select>
            </div>

            <div class="form-group">
                <label for="exampleInputPassword1">Time</label>
                <input type="time" name="count_time" class="form-control" id="exampleInputPassword1">
            </div>

            <div class="form-group">
                <label for="exampleInputPassword1">Count</label>
                <input type="number" name="room_counts" class="form-control" id="exampleInputPassword1" placeholder="Count">
            </div>

            <div class="button-container">
                  <button type="submit" class="btn btn-primary">Submit</button>
            </div>       
          
        </form>

Here is the node js code:

app.post('/count', (req,res)=>{

    console.log(req.body.session);
    console.log(req.body);
   
    res.redirect('/count');

});

Here is the response on the console:

Learning
{
  room: 'Kenmore',
  session: 'Learning',
  count_time: '13:33',
  room_counts: '100'
}

session: Learning. Is supposed to be session: Learning Web Development. I want to use the value from session to compare it with what's in the database. Any help would be appreciated.

1 Answers

Explain

Take this line for example:

<option class="rooms" value={{this.session_name}}>{{this.session_name}}</option>

If this.session_name is learning web development then it will become:

<option class="rooms" value=learning web development>{{this.session_name}}</option>

And value is just 'learning', web and development will be considered as attributes of option tag like class or value (You can see the colors of the text)

Action

You should put the double quotes around the variable

<option class="rooms" value="{{this.session_name}}">{{this.session_name}}</option>

It will become:

<option class="rooms" value="learning web development">{{this.session_name}}</option>
Related