First of all, why this isn't a duplicate: I am asking about handling multiple versions of a submission using Node. I didn't find any post asking that.
Basing on this I built this:
<form method="post">
<% for(let i = 0; i < websites.length; i++){ let website = websites[i]; %>
<fieldset>
<label for="website<%= i %>" class="col-sm-2">Website <%= i + 1 %></label>
<input class="website" name="website<%= i %>" id="website<%= i %>" value="<%= website %>" type="text"/>
<span style="color: red"><%= errorMsgs[i] %></span>
<a href="/websites/edit/<%= i %>" class="btn btn-info">Edit</a>
<a href="/websites/delete/<%= i %>" class="btn btn-danger confirmation hide">Delete</a>
<div id="removeBtn" class="btn btn-danger confirmation">Remove</div>
</fieldset>
<% } %>
<input type="submit" class="btn btn-primary col-sm-offset-2" value="Generate a report" name="generateReport"
data-toggle="modal" data-target="#exampleModal">
<input type="submit" class="btn btn-primary col-sm-offset-2" value="Save websites" name="saveWebsites">
<!-- Modal -->
</form>
I am using EJS, but I don't think it matters in this case.
And this is my back end:
console.log(req.generateReport);
console.log(req.saveWebsites);
if(req.generateReport!==null){
console.log('report');
return 0;
}
else if(req.saveWebsites!==null){
console.log('save');
return 0;
}
I was trying to use the answer I put a link to earlier, but it turns out, that the req.saveWebsites
and req.generateReport
properties are both undefined... So how do I handle it with Node?
I do not want to use AJAX, because I need it to work with JS disabled.