jbrinley / wp-forms Goto Github PK
View Code? Open in Web Editor NEWAn API for creating and processing forms in WordPress
An API for creating and processing forms in WordPress
Hey,
I've a simple form with three radio elements. My issue is that if validation fails on any of the elements in the form, the state of the radio elements is lost. This does not happen for the text elements. I'm wondering is there something i'm expected as the form developer to handle this case or should the framework be expected to handle this.
My code
$gender_drop_down = WP_Form_Element::create('radios')->set_name('bhaa_gender')
->set_label('Gender')->set_classes(array('radio-inline'))
->add_option('M','M')
->add_option('W','W');
and a screen shot of the form
Note - The gender field was selected before this form was submitted. I just want to avoid have to re-check the three radio buttons each time.
One should be able to create a paginated form, with each page's fields possibly dependent on values submitted on previous pages.
Hey,
I've been looking at this code trying to understand how i can tell the $element type within my filter method implementation. Instead of applying a callback here I think it would be better to have an optional method on each element which would be defined as part of the form definition. The default of course would be 'div'.
class WP_Form_Decorator_HtmlTag extends WP_Form_Decorator {
// TODO: some sort of callback for context-aware attributes
public function render( WP_Form_Component $element ) {
$args = wp_parse_args(
$this->args,
array(
// apply_filters('wp_form_htmltag_default', 'div'),
'tag' =>$element->get_htmltag_default(),
'attributes' => array(),
)
);
return $this->open_tag($args['tag'], $args['attributes']) . $this->component_view->render($element) . $this->close_tag($args['tag']);
}
```ruby
Hey,
I think an examples folder with sample forms might be useful to explain some of the more complicated features of your framework.
I'd be interested to see an example where the form elements are decorated in such a way that the final form would appear as a grid once css or js styling has been applied.
Regards,
Paul
This is probably not a real issue for wp-forms but I just lost an hour resolving the following bug and I just wanted to document it somewhere.
In my form, I had a field named member
. I also have a custom post type with the same name. I don’t know exactly why but if I submit the form and the validation doesn’t pass, I get redirected to the correct URL with the 404 template being displayed. I’ve tested with other custom post types and the behaviour is similar. It doesn’t seems to happen with fields named post
or page
though.
I’ve renamed the field "member_type" and now it works perfectly. Do you have any idea where this conflict could come from and if it could be prevented by wp-forms somehow?
Thanks for this great and highly customisable API by the way.
Hey,
i keep getting this error
Fatal error: Call to a member function get_validators() on a non-object in C:\oconnellp\wamp\wordpress\wp-content\plugins\wp-forms-master\classes\WP_Form_Submission.php on line 110
1 0.0003 680776 {main}( ) ..\index.php:0
2 0.0004 685624 require( 'C:\oconnellp\wamp\wordpress\wp-blog-header.php' ) ..\index.php:17
3 0.0007 711720 require_once( 'C:\oconnellp\wamp\wordpress\wp-load.php' ) ..\wp-blog-header.php:12
4 0.0010 742544 require_once( 'C:\oconnellp\wamp\wordpress\wp-config.php' ) ..\wp-load.php:29
5 0.0016 876344 require_once( 'C:\oconnellp\wamp\wordpress\wp-settings.php' ) ..\wp-config.php:120
6 0.3729 60237384 do_action( ) ..\wp-settings.php:308
7 0.5309 73860472 call_user_func_array ( ) ..\plugin.php:406
8 0.5309 73860504 WP_Form_Listener->check_form_submission( ) ..\plugin.php:406
9 0.5320 73927632 WP_Form_Submission->is_valid( ) ..\WP_Form_Listener.php:20
10 0.5320 73927632 WP_Form_Submission->validate( ) ..\WP_Form_Submission.php:17
when i run this form class in my plugin. Just wondering can you spot any error with how i register my validator method?
class Raceday_Registration_Form{
public function build_form(WP_Form $form) {
$args = func_get_args();
call_user_func_array(array($this, 'bhaaRegisterForm'), $args);
}
/**
*
* http://jsfiddle.net/kY5LL/12/
* @param unknown $form
*/
private function bhaaRegisterForm(WP_Form $form) {
error_log('bhaaRegisterForm');
$firstname = WP_Form_Element::create('text')->set_name('firstname')->set_label('First Name')->set_id('firstname');
$lastname = WP_Form_Element::create('text')->set_name('lastname')->set_label('Last Name')->set_id('lastname');
$submit = WP_Form_Element::create('submit')
->set_name('submit')
->set_label('Register Runner');
$form->add_element( WP_Form_Element::create('number')
->set_name('number')->set_id('number')
->set_label('Race Number'));
$form->add_element( WP_Form_Element::create('number')
->set_name('runner')->set_id('runner')
->set_label('BHAA ID'));
$form->add_element($firstname);
$form->add_element($lastname);
$form->add_element($submit);
$form->add_class('form-example');
$form->add_validator(array($this,'bhaa_validation_callback'));
$form->add_processor(array($this,'bhaa_processing_callback'));
}
public function filter_button_views( $decorators, $element ) {
if ( $element->type == 'text' ) {
$decorators = array(
'WP_Form_Decorator_HtmlTag' => array('tag' => 'div',
'attributes' => array( 'class' => 'control-group' )),
);
}
return $decorators;
}
public function bhaa_processing_callback( WP_Form_Submission $submission, WP_Form $form ) {
$first_name = $submission->get_value('firstname');
// do something with $first_name
error_log('firstname '.$first_name);
// redirect the user after the form is submitted successfully
$submission->set_redirect('');//home_url('aPage'));
}
public function bhaa_validation_callback( WP_Form_Submission $submission, WP_Form $form ) {
error_log('bhaavalidation_callback');
//if ( $submission->get_value('first_name') != 'Jonathan' ) {
// $submission->add_error('first_name', 'Your name should be Jonathan');
//}
}
}```
It would be good if the WP_Form could support a FieldSet elements. This would allow groups of form elements to be grouped, so that css styling of the form could be more easily controlled.
A new WP_Form_Element_FieldSet would be created which would support the normal decorators. It would also support a list of form elements.
A new WP_Form_View_FieldSet would render the element, and then iterate the list of form elements calling render on each.
Do esc_textarea()
for <textarea>
content.
$value = esc_textarea( $attributes['value'] );
Hey,
Would it be possible to document how to redirect to same form post submission
Regards,
Paul
I can create a checkbox group like so:
$checkboxes = WP_Form_Element::create( 'checkboxes' )
->set_name( 'interests' )
->set_label( 'Interests' )
->add_option( 'something,'Something' )
->add_option( 'something_else', Something else' );
Cool.
But if I'm grabbing data from the database (after the form has been submitted), how do I show which options have been selected.
$checkboxes->set_attribute( 'checked', 'checked' );
Will sets all the attributes to checked. There doesn't seem to be anything I can find in the docs about this. Any tips!?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.