Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// get all instances of a form on the post
const matches = document.querySelectorAll(".gform_wrapper form")
// we are using vue.js here with the slug of the current post in state
const slug = store.state.currentPost.slug
// loop through each form on the post
matches.forEach(function(match) {
// get the value of the id of the form
let gformID = match.getAttribute("id")
// get only the form number off the gravity form using regex
let isolatedID = /([1-9][0-9]*)/.exec(gformID)
// set the action of the current form using the slug and the current form id
match.setAttribute("action", `/${slug}/#gf_${isolatedID[0]}`)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.