mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.71k stars 846 forks source link

Getting error while setting "Value" attribute in hidden input form using <%= or <%- tag #637

Closed gabo71096 closed 2 years ago

gabo71096 commented 2 years ago

I'm building an ecommerce web app attempt, and never had any issues with the <%= tag, I have srcs, hrefs and many attributes assigned with EJS, but when I try to use it in the value attribute in a form, I get an error telling me that "id is not defined" (id is the name that I use when rendering the form from NodeJS using Express). The weird thing is that after getting the 500 error (logged using Morgan), I still get to add a document to my MongoDB database using the data from the form, including the hidden "id" that's getting me the error. Also I can see the hidden value in the form page using developer tools, it's included correctly.

devTools errorPage error500_dbInsertion ejsFormPage

mde commented 2 years ago

EJS really just interprets JavaScript. The only reason I can think for getting that error is that the id variable in your locals is genuinely undefined. How are you invoking the EJS render, and have you verified that that variable is defined in your locals?

gabo71096 commented 2 years ago

First of all, thanks for the response and for your hard work! I checked many times the POST route, because that's the one that was giving me the 500 error, and realize that after the insertion, I rendered again the same page, but I didn't include the id in that sentence. Hence, the undefined error.

I'm sorry if I took time from you, and I thank you greatly again for your help.

image