title: How to add a button with an Update function using Node and Mongoose
body: <p>I have created a mongoose db with events, each event is inside a bootstrap card. I am trying to figure out a way how can I redirect admin to a page where he can update the event-card and saved to my <code>mongoose db</code>.</p>
  <p>The issue I have is that I already have a form for that card with a delete action and I need to be able to have another one. What I thought is to add a link which will redirect to an <code>update_page.ejs</code> where admin will can make changes to the form of that event and save them.</p>
  <p><strong>Code for admin.ejs page</strong></p>
  <pre><code>&lt;% events.forEach( function (event) { %&gt;
        &lt;form class=&quot;form-events&quot; action=&quot;/delete&quot; method=&quot;post&quot;&gt;
  
          &lt;div class=&quot;card col-lg-3&quot; style=&quot;width: 18rem;&quot;&gt;
  
            &lt;img class=&quot;card-img-top&quot;&gt;
            &lt;div class=&quot;card-body&quot;&gt;
  
              &lt;h5 class=&quot;card-title&quot;&gt;&lt;%= event.title %&gt;&lt;/h5&gt;
              &lt;p class=&quot;card-text&quot;&gt;&lt;%= event.description %&gt;&lt;/p&gt;
              &lt;p class=&quot;card-text&quot;&gt;&lt;%= event.date %&gt; &lt;/p&gt;
              &lt;p class=&quot;card-text&quot;&gt;&lt;%= event.capacity %&gt;&lt;/p&gt;
  
              &lt;a href=&quot;/create_event&quot; class=&quot;btn btn-primary&quot;&gt;Update&lt;/a&gt;
              &lt;button name=&quot;deleteBtn&quot; value=&quot;&lt;%=event._id%&gt;&quot; type=&quot;submit&quot; class=&quot;btn btn-danger&quot;&gt;Delete&lt;/button&gt;
            &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;% }); %&gt;
        &lt;/form&gt;
  </code></pre>
  <p><a href="https://i.stack.imgur.com/mIycz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mIycz.png" alt="admin.ejs" /></a></p>
  <p>Currently the <code>update button</code> redirects here:</p>
  <p><a href="https://i.stack.imgur.com/ge1xC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ge1xC.png" alt="create_event.ejs" /></a></p>
  <p>where is basically a creation of an event.</p>
  <p>A simple solution I thought is just to add another button near the create page like update.
  So my first problem is that how can I after redirecting from my <code>admin.ejs</code> to <code>create_page.ejs</code>
  have the from completed by the event pressed otherwise the form contents will be empty, and which <code>app.() method</code> I must use <code>( POST, PATCH )</code> and finally is it even possible to add 2 actions to one form?</p>
  <p><strong>app.js code</strong></p>
  <pre><code>//Create new event route.
  app.post(&quot;/create_event&quot;, function (req, res) {
  
    const event = new Event({
      title: req.body.ev_title,
      description: req.body.ev_desc,
      date: req.body.ev_date,
      capacity: req.body.ev_cap,
    });
  
    event.save(function (err) {
      if (err) {
        console.log(err);
      } else {
        res.redirect(&quot;/admin&quot;);
      }
    });
  });
  
  // Delete an event
  app.post(&quot;/delete&quot;, function (req, res) {
  
    const deletedItemId = req.body.deleteBtn;
  
    Event.findByIdAndDelete(deletedItemId, function (err) {
      if (!err) {
        console.log(&quot;Successfully deleted&quot;);
        res.redirect(&quot;/admin&quot;);
      } else {
        console.log(err);
      }
    });
  });
  </code></pre>
  <p>P.S my solution for the <code>DELETE route</code> is correct?
  I am sorry for all the specifics, but I am totally new to this and have this project deadline coming up
  googled all this method but the docs seemed a bit too technical right now for me.</p>