• Resolved michaelsmartmove

    (@michaelsmartmove)


    To whom it may concern,

    I am currently busy developing an addon for WP Forms and I want to be able to add a number field to the Field Options -> General Settings within the WP Forms Builder. Sadly the field_element() function doesn’t allow the number field type.

    I am not sure if here is the correct place to enquire about potentially getting an update for this. I can add the needed code to the WP Forms plugin myself to add support for the number field type, but should WP Forms push an update in the future, it will overwrite my change.

    The Code that should be added to the class-base.php is as follows:

    // Number input.
    case 'number':
    $type = ! empty( $args['type'] ) ? esc_attr( $args['type'] ) : 'number';
    $placeholder = ! empty( $args['placeholder'] ) ? esc_attr( $args['placeholder'] ) : '';
    $before = ! empty( $args['before'] ) ? '<span class="before-input">' . esc_html( $args['before'] ) . '</span>' : '';
    $after = ! empty( $args['after'] ) ? '<span class="after-input sub-label">' . esc_html( $args['after'] ) . '</span>' : '';

    if ( ! empty( $before ) ) {
    $class .= ' has-before';
    }

    if ( ! empty( $after ) ) {
    $class .= ' has-after';
    }

    $output = sprintf( '%s<input type="%s" class="%s" id="wpforms-field-option-%d-%s" name="fields[%d][%s]" value="%s" placeholder="%s" %s>%s', $before, $type, $class, $id, $slug, $id, $slug, esc_attr( $args['value'] ), $placeholder, $attrs, $after );
    break;
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Ralden Souza

    (@rsouzaam)

    Hi @michaelsmartmove,

    Thanks for reaching out!

    I have escalated your question to our development team, and I will get back to you as soon as we have an update to help with your request.

    Thanks!

    Plugin Support Kenneth Macharia

    (@kmacharia)

    Hey @michaelsmartmove,

    Thank you for bringing this up! Our team has reviewed this issue and it looks like the number field type is already supported. We recommend creating a field with $option = ‘text’ and supply the type as number in the $args as shown below:

    'type' => 'number'

    For reference, please take a look at the number slider min and max options in wp-content/plugins/wpforms/includes/fields/class-number-slider.php?on line 154:

    $min = $this->field_element(
    'text',
    $field,
    [
    'type' => 'number',
    'slug' => 'min',
    'class' => 'wpforms-number-slider-min',
    'value' => ! empty( $field['min'] ) ? (float) $field['min'] : self::SLIDER_MIN,
    ],
    false
    );

    $max = $this->field_element(
    'text',
    $field,
    [
    'type' => 'number',
    'slug' => 'max',
    'class' => 'wpforms-number-slider-max',
    'value' => ! empty( $field['max'] ) ? (float) $field['max'] : self::SLIDER_MAX,
    ],
    false
    );

    I hope this helps! Could you please let me know if you have other questions?

    Thank you!

    Thread Starter michaelsmartmove

    (@michaelsmartmove)

    Hi @kmacharia,

    Thanks so much. That solution worked perfectly and I will try to keep it in mind for the future.

    Plugin Support Kenneth Macharia

    (@kmacharia)

    Hey @michaelsmartmove

    We’re thrilled to hear your issue is resolved! Thanks for letting us know.

    Your experience is important to us, and we’d love to hear what you think about using WPForms.  Would you mind sharing a quick review on www.remarpro.com? It only takes a minute and helps us keep improving!

    Here’s the link to leave a review and in case you’d like some guidance, this article walks you through the process.

    We appreciate your time and feedback!

    Thanks ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Add Number Field Element’ is closed to new replies.