Last active
November 18, 2019 01:35
-
-
Save shrinkray/acf91e64645d6ff300e17d9d34941bbc to your computer and use it in GitHub Desktop.
With a Gravity Form added, script adds input inside Form and replaces DOM input with button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $id_or_title = 12; | |
| $tabindex = true; | |
| gravity_form( $id_or_title, $display_title = false, | |
| $display_description = true, | |
| $display_inactive = false, | |
| $field_values = null, | |
| $ajax = false, | |
| $tabindex, | |
| $echo = true ); | |
| ?> | |
| <script> | |
| /** | |
| * This part was not implemented, but could be later | |
| * @type {string} | |
| */ | |
| const inputsBlock = ` | |
| <input type="hidden" name="elqFormName" value="ContactUs"> | |
| <input type="hidden" name="elqSiteID" value="NUMBER"> | |
| <input type="hidden" name="elqCustomerGUID" value=""> | |
| <input type="hidden" name="elqCookieWrite" value="0"> | |
| `, | |
| placeBlockBefore = document.querySelector('#gform_12 .gform_heading'), | |
| buttonBlock = ` | |
| `; | |
| placeBlockBefore.insertAdjacentHTML("beforebegin", inputsBlock); | |
| // this was implemented below an embedded gform and it worked! | |
| // Template strings made a huge improvement over previous code | |
| /* I was excited that this worked. | |
| * This code replaces the existing <input ...> with <button ..> because you cannot add icons to inputs | |
| * Adding classes, btn-conversion, blue3, and d-flex are for presentation | |
| * Variables in template strings aid in making changes in just one place | |
| */ | |
| const elem = document.querySelector('#gform_submit_button_11'), | |
| newElem = document.createElement('button'), | |
| btnId = '11', | |
| eventKeyCode = '13', | |
| conversionText = 'Start a Conversation'; | |
| newElem.setAttribute("type", "submit"); | |
| newElem.setAttribute("id", "gform_submit_button_11"); | |
| newElem.setAttribute("class", "gform_button button btn-conversion blue3 d-flex"); | |
| newElem.setAttribute("value", "Start a Conversation"); | |
| newElem.setAttribute("tabindex", "1"); | |
| newElem.setAttribute("onclick", `if(window["gf_submitting_${btnId}"]){return false;} window["gf_submitting_${btnId}"]=true; `); | |
| newElem.setAttribute("onkeypress", `if( event.keyCode == ${eventKeyCode} ){ if(window["gf_submitting_${btnId}"]){return false;} window["gf_submitting_${btnId}"]=true; jQuery("#gform_${btnId}").trigger("submit",[true]); }`); | |
| newElem.innerHTML = ` | |
| <span class="fa-lg"> | |
| <i class="fa fa-comments-o " aria-hidden="true"></i> | |
| </span> | |
| <span class="conversion-text mega-wide">${conversionText}</span> | |
| `; | |
| elem.parentNode.replaceChild(newElem , elem); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment