I have the following partial as part of my assignment to show a list of events on my website, the problem is that I want to use the value called event name in a mongo dB query so I can append the users username to the attending array based on the name of the event
<ul>
<!-- for each user-->
<% events.forEach(function(event) { %>
<form action="/attend" method="post">
<div class="Events">
<div class="Post" id="Post1">
<div class="PostTitle" name = "eventname"><%= event.name %></div>
<div class="PostDate" name = "date"> <%= event.date %></div>
<div class="PostDescription"><%= event.description %></div>
<div class="PostAttending" name="AttendingNum"><%= event.attendingusers.length%></div>
<div class="PostAttendingSymbol"><span>👤</span></div>
<button class="editbutton" type="submit">Attend</button>
</div>
</div>
</form>
<% }); %>
during testing i have tried this code to get the value but it is coming back as undefined
app.post('/attend', function(req, res){
var test = {
"event" : req.body.eventname}
var user = req.session.currentuser
console.log(JSON.stringify(test))
console.log(JSON.stringify(user))
});
any help would be great as I planned on using a process like this to delete events too
There is no name attribute for div. If you need to uniquely identify one, use id. In your case you can also use input of hidden type with the value assigned like this:
<input type="hidden" name="eventname" value="<%= event.name %>">