Skip to content

Instantly share code, notes, and snippets.

@vanbernaert
Forked from richardW8k/button_filters.php
Created May 12, 2014 16:29
Show Gist options
  • Select an option

  • Save vanbernaert/e9ac6ddaa13de40dde6c to your computer and use it in GitHub Desktop.

Select an option

Save vanbernaert/e9ac6ddaa13de40dde6c to your computer and use it in GitHub Desktop.

Revisions

  1. @richardW8k richardW8k revised this gist Jan 28, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion button_filters.php
    Original file line number Diff line number Diff line change
    @@ -21,5 +21,5 @@ function input_to_button( $button, $form ) {
    $new_button->setAttribute( $attribute->name, $attribute->value );
    }
    $input->parentNode->replaceChild( $new_button, $input );
    return $dom->saveHtml($new_button);
    return $dom->saveHtml( $new_button );
    }
  2. richardvav renamed this gist Jan 12, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions button_filters → button_filters.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    <?php
    /**
    * Filters the next, previous and submit buttons.
    * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
  3. richardvav revised this gist Jan 12, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion button_filters
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
    * @param string $button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered submit button.
    * @return string The filtered button.
    */
    add_filter( 'gform_next_button', 'input_to_button', 10, 2 );
    add_filter( 'gform_previous_button', 'input_to_button', 10, 2 );
  4. richardvav revised this gist Jan 11, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions button_filters
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    /**
    * Filters the next, previous and submit buttons.
    * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
    * @param string $button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered submit button.
  5. richardvav revised this gist Jan 11, 2014. 1 changed file with 5 additions and 38 deletions.
    43 changes: 5 additions & 38 deletions button_filters
    Original file line number Diff line number Diff line change
    @@ -1,46 +1,13 @@
    /**
    * Filters the next button.
    * @see input_to_button()
    * @param string $next_button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered next button.
    */
    add_filter( 'gform_next_button', 'next_input_to_button', 10, 2 );
    function next_input_to_button( $next_button, $form ) {
    GFCommon::log_debug( "next_input_to_button(): {$next_button}" );
    return input_to_button( $button = $next_button );
    }

    /**
    * Filters the previous button.
    * @see input_to_button()
    * @param string $previous_button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered previous button.
    */
    add_filter( 'gform_previous_button', 'previous_input_to_button', 5, 2 );
    function previous_input_to_button( $previous_button, $form ) {
    return input_to_button( $button = $previous_button );
    }

    /**
    * Filters the submit button.
    * @see input_to_button()
    * Filters the next, previous and submit buttons.
    * @param string $button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered submit button.
    */
    add_filter( 'gform_submit_button', 'submit_input_to_button', 10, 2 );
    function submit_input_to_button( $button, $form ) {
    return input_to_button( $button );
    }

    /**
    * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
    * @param string $button Contains the <input> tag to be filtered.
    * @return string The filtered button.
    */
    function input_to_button( $button ) {
    add_filter( 'gform_next_button', 'input_to_button', 10, 2 );
    add_filter( 'gform_previous_button', 'input_to_button', 10, 2 );
    add_filter( 'gform_submit_button', 'input_to_button', 10, 2 );
    function input_to_button( $button, $form ) {
    $dom = new DOMDocument();
    $dom->loadHTML( $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
  6. richardvav created this gist Jan 11, 2014.
    56 changes: 56 additions & 0 deletions button_filters
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    /**
    * Filters the next button.
    * @see input_to_button()
    * @param string $next_button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered next button.
    */
    add_filter( 'gform_next_button', 'next_input_to_button', 10, 2 );
    function next_input_to_button( $next_button, $form ) {
    GFCommon::log_debug( "next_input_to_button(): {$next_button}" );
    return input_to_button( $button = $next_button );
    }

    /**
    * Filters the previous button.
    * @see input_to_button()
    * @param string $previous_button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered previous button.
    */
    add_filter( 'gform_previous_button', 'previous_input_to_button', 5, 2 );
    function previous_input_to_button( $previous_button, $form ) {
    return input_to_button( $button = $previous_button );
    }

    /**
    * Filters the submit button.
    * @see input_to_button()
    * @param string $button Contains the <input> tag to be filtered.
    * @param object $form Contains all the properties of the current form.
    * @return string The filtered submit button.
    */
    add_filter( 'gform_submit_button', 'submit_input_to_button', 10, 2 );
    function submit_input_to_button( $button, $form ) {
    return input_to_button( $button );
    }

    /**
    * Replaces the forms <input> buttons with <button> while maintaining attributes from original <input>.
    * @param string $button Contains the <input> tag to be filtered.
    * @return string The filtered button.
    */
    function input_to_button( $button ) {
    $dom = new DOMDocument();
    $dom->loadHTML( $button );
    $input = $dom->getElementsByTagName( 'input' )->item(0);
    $new_button = $dom->createElement( 'button' );
    $button_span = $dom->createElement( 'span', $input->getAttribute( 'value' ) );
    $new_button->appendChild( $button_span );
    $input->removeAttribute( 'value' );
    foreach( $input->attributes as $attribute ) {
    $new_button->setAttribute( $attribute->name, $attribute->value );
    }
    $input->parentNode->replaceChild( $new_button, $input );
    return $dom->saveHtml($new_button);
    }