Custom code to hide new forms after form submission Answered
How can I implement custom code so that every time a user submits a form on a CMS page, the item’s ID is added to the user’s metadata and the form is not shown to the user anymore?
How can I implement custom code so that every time a user submits a form on a CMS page, the item’s ID is added to the user’s metadata and the form is not shown to the user anymore?
Comments
10 comments
Hello Alican 👋🏼
Great question! The easiest no-code way I can think of is when they submit a form they change to another “free plan” so as they upgrade any content from the last membership automatically hides. To add the item’s ID you could create a profile form to add the item’s ID.
You could also try and use Webflow’s filter function
However I’m not really sure if that’s a good solution for you depending on your needs. Can you share a little more information and use-case for your users?
Unfortunately, this situation probably requires code. My users apply for jobs, and by adding the job they applied to their metadata, I should prevent them from applying a second time for the same job. I should also show the jobs they have applied for on their profile. I had custom code on MS 1.0 that did this. Code basically worked like this, it checked if the item’s ID in member’s metadata. If it was in metadata it hid the applying form. If not it showed the form and once it was submitted it was then added to metadata.
ah okay, if you already have code for this in 1.0, we have an article here that you could guide you in converting your code to 2.0 🎊
I kinda need some help on the code. This is the code I came up but it doesn’t work as I wanted it to work. I manually added applied metadata in Memberstack as “applied: 12”, and console.log(metadata) shows as {applied: '12', fileNames: Array(0)}. It’s not in fileNames though. Also submitting a form doesn’t add anything to metadata. I don’t know what I’m doing wrong. If you want I can provide the older code for 1.0.
Thank you in advance. 🙏
Hopefully this works for you. (It’s untested but it’s based on working code).
Here’s some helper functions for the “Footer code” region in settings (will be available site-wide on all pages):
And the page code:
I recommend storing things like Arrays in a Member’s JSON and not in Metadata.
Hopefully this works first try but there might be a slight oversight. Let me know how you go.
Unfortunately it didn’t work
Hmm, I just tested it and it worked for me, I just changed the itemID variable to const itemID = 1234; while I test it. Maybe try that. What does your browser’s console say?
Ha! That worked out great. Thank you so much
If anyone else lands here, quick reminder:
You can no longer update metadata from the front end anymore. We removed that ability a couple months ago for security.
Also Marc is correct that storing arrays of data is best used in member JSON. 👌
No worries
Please sign in to leave a comment.