title: Displaying server side validation error message on a bootstrapped ejs form
body: <p>I am trying to conditionally display an error message if a user enters a URL string which isn’t a valid URL into a bootstrap form field.</p>
  <p>From the validationResult I am sending the errors over to the EJS template as an array of error objects as per express-validator docs. I have other form fields being validated as well so there could be more than one error in the array.</p>
  <pre><code>app.post('/create', [
    body('imgURL').isURL()
      .withMessage(‘Must be valid URL’)
  ], (req, res) =&gt; {
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.render(‘form’, { errors: errors.array() });
    }
  })
  </code></pre>
  <p>In my EJS template Im using standard bootstrap client side validation but also want to be able to display server errors as well. How can I conditionally render the invalid-feedback div with the server message. And also toggle the input element class ‘is-invalid’?</p>
  <p>Since errors might be an array do I have to loop through the array and check the error object param field (i.e error.param === ‘imgURL’)? Would I have to repeat this loop for every form field?</p>
  <pre><code>&lt;div&gt;
   &lt;label for=&quot;imgURL&quot;&gt;Image URL&lt;/label&gt;
   &lt;input type=&quot;text&quot; class=&quot;form-control is-invalid&quot; id=&quot;imgURL&quot; required&gt;
    &lt;div class=&quot;invalid-feedback&quot;&gt;  
      Message sent from server here.   
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  <p>Alternatively is there a better way?
  Thanks!</p>