Skip to content

Commit

Permalink
Adds "url" input type for View settings
Browse files Browse the repository at this point in the history
This takes advantage of browser validation (related to #2159), while making a very small change.

I considered updating the `GravityView_FieldType` abstract class to add an `input_type` and just use the existing `GravityView_FieldType_text` class, but I determined that this was cleaner.
  • Loading branch information
zackkatz committed Nov 7, 2024
1 parent 5907106 commit f2ee806
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 4 additions & 3 deletions future/includes/class-gv-settings-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ public static function defaults( $detailed = false, $group = null ) {
'label' => __( 'No Entries Redirect URL', 'gk-gravityview' ),
'group' => 'default',
'desc' => __( 'If there are no entries to show, the user will be taken to this URL.', 'gk-gravityview' ),
'type' => 'text',
'type' => 'url',
'class' => 'code widefat',
'value' => '',
'placeholder' => 'https://www.example.com',
'requires' => 'no_entries_options=2',
'show_in_shortcode' => true,
),
'no_search_results_text' => array(
'label' => __( '"No Search Results" Text', 'gk-gravityview' ),
Expand Down Expand Up @@ -509,7 +510,7 @@ public static function defaults( $detailed = false, $group = null ) {
'label' => __( 'Edit Entry Redirect URL', 'gk-gravityview' ),
'group' => 'default',
'desc' => __( 'After editing an entry, the user will be taken to this URL.', 'gk-gravityview' ),
'type' => 'text',
'type' => 'url',
'class' => 'code widefat',
'value' => '',
'placeholder' => 'https://www.example.com/landing-page/',
Expand Down Expand Up @@ -595,7 +596,7 @@ public static function defaults( $detailed = false, $group = null ) {
'label' => __( 'Delete Entry Redirect URL', 'gk-gravityview' ),
'group' => 'default',
'desc' => __( 'After deleting an entry, the user will be taken to this URL.', 'gk-gravityview' ),
'type' => 'text',
'type' => 'url',
'class' => 'code widefat',
'value' => '',
'placeholder' => 'https://www.example.com/landing-page/',
Expand Down
30 changes: 30 additions & 0 deletions includes/admin/field-types/type_url.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* url input type
*/
class GravityView_FieldType_url extends GravityView_FieldType_text {

function render_input( $override_input = null ) {

if ( isset( $override_input ) ) {
echo $override_input;
return;
}

$class = '';

$show_mt = $this->show_merge_tags();

if ( $show_mt && false !== $this->field['merge_tags'] || 'force' === $this->field['merge_tags'] ) {
$class = 'gv-merge-tag-support mt-position-right mt-hide_all_fields ';
}
$class .= \GV\Utils::get( $this->field, 'class', 'widefat' );
$placeholder = \GV\Utils::get( $this->field, 'placeholder' );
?>
<input name="<?php echo esc_attr( $this->name ); ?>" placeholder="<?php echo esc_attr( $placeholder ); ?>" id="<?php echo $this->get_field_id(); ?>" type="url" value="<?php echo esc_attr( $this->value ); ?>" class="<?php echo esc_attr( $class ); ?>">
<?php
}
}



0 comments on commit f2ee806

Please sign in to comment.