wordpress - How to make Titan Framework text field required -
i using titan framework custom plugin wrote. there settings page has tab , on there text field:
array( 'name' => 'slug', 'id' => 'my_slug', 'type' => 'text', 'default' => 'my-slug', 'desc' => 'the slug.', ),
this text field allows user specify slug plugin's frontend ui. problem user can clear field out nothing , save settings results in error.
i understand can trap condition in php code when setting option used. understand done using jquery enforce value being specified, seem there should best practice solution.
can tell me proper way ensure field has value?
the user can save empty , yes can prevent js. because there no "pre save" filter, 1 way address to method mentioned, add placeholder
attribute field give illusion of value when empty (this better user experience).
array( 'name' => 'slug', 'id' => 'my_slug', 'type' => 'text', 'default' => 'my-slug', 'desc' => 'the slug.', 'placeholder' => 'post', ),
then check empty
when getting value.
$slug = $titan->getoption( 'my_slug' ); if ( empty( $slug ) ) { $slug = 'post'; }
Comments
Post a Comment