How do i access ejs data in a form while using express

Viewed 31047

In the following code, I display the following HTML file upon user requests. I also want to access the clubname and type datavalues inside my app.post() function in my app.js file.

<!DOCTYPE html>
<html>
<head>
    <title><%= title %></title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<% include templates/adminheader.ejs %>
<h1>Respond to Club Requests</h1>

<form name="clubform" method="post">
    <% for (var i in clubreq){%>
        Club Name:<%= clubreq[i].clubname %><br><br>//I want to access this variable in my app.post() function
        Club Type:<%= clubreq[i].type %><br><br>
        <input type="submit" value="accept"/><br><br><hr>
    <%} %>
</form>

</body>
</html>

Inside app.js. Here I am rendering the HTML file upon user request

app.get('/clubreq', function(req, res, next){
        res.render('clubreq', {
            title: 'Club Requests',
            "clubreq" : docs
        });       
});
app.post('/clubreq', function(req, res, next){
    //I want to access clubname and type datavariables here and store it in my mongodb database
});
1 Answers
Related