Skip to content

Instantly share code, notes, and snippets.

@chrismcintosh
Created August 27, 2019 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismcintosh/f390f9a3985d635290b25f67476e024e to your computer and use it in GitHub Desktop.
Save chrismcintosh/f390f9a3985d635290b25f67476e024e to your computer and use it in GitHub Desktop.
// 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