[wp-trac] [WordPress Trac] #43003: HTML5 "required" attribute in Widget form() fails in ajax-actions.php during save
WordPress Trac
noreply at wordpress.org
Sat Dec 30 22:47:50 UTC 2017
#43003: HTML5 "required" attribute in Widget form() fails in ajax-actions.php
during save
--------------------------+-----------------------------
Reporter: Andy Schmidt | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 4.9.1
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
If a field on a widget settings form uses the HTML5 "required" attribute,
then saving the settings will only APPEAR to have "saved" the form
content.
In reality, the result is:
{{{
Undefined index: widgetbaseid-nn in wp-admin\includes\ajax-actions.php on
line 1998
Stack trace:
1. {main}() E:\Hosted Sites\wwwroot\wp-admin\admin-ajax.php:0
2. do_action() E:\Hosted Sites\wwwroot\wp-admin\admin-ajax.php:97
3. WP_Hook->do_action() E:\Hosted Sites\wwwroot\wp-includes\plugin.php:453
4. WP_Hook->apply_filters() E:\Hosted Sites\wwwroot\wp-includes\class-wp-
hook.php:310
5. wp_ajax_save_widget() E:\Hosted Sites\wwwroot\wp-includes\class-wp-
hook.php:286
}}}
Simply removing the "required" attribute from this input field, will
circumvent the bug:
{{{#!php
<?php
<input class="widefat" type="text" required="required" id="<?php
echo \esc_attr( $this->get_field_id( 'addtlfld' ) ); ?>" name="<?php echo
\esc_attr( $this->get_field_name( 'addtlfld' ) ); ?>" value="<?php echo
\esc_attr( $old_settings[ 'addtlfld' ] ?? '' ); ?>">
}}}
Attached is a plugin with two versions of the widget - one has regular
text field, the other has the same text field but uses the "required"
attribute.
Uses PHP 7.1 syntax.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43003>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list