mirror of
https://github.com/WordPress/five-for-the-future.git
synced 2025-07-04 18:05:45 +03:00
Create Pledge: Make form functional (#31)
This broadly enables & styles the pledge forms across the frontend and wp-admin. - Switches field `readonly` control to a variable called `$readonly` - Create `PledgeMeta\get_pledge_meta()` which will fetch data from `$_POST`, a pledge post, or defaults. - Add Number of Employees field - Update form content to match mockup: - fields now have help text - success message uses content from mockup - logo field is moved to the "org info" section - Style form in theme, add some similar styles to the admin Fixes #7, fixes #28
This commit is contained in:
parent
0111c36db4
commit
0f675ae6c3
13 changed files with 313 additions and 127 deletions
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
*
|
||||
* Render and process the pledge forms.
|
||||
*/
|
||||
|
||||
namespace WordPressDotOrg\FiveForTheFuture\PledgeForm;
|
||||
|
@ -25,6 +25,7 @@ function render_form_new() {
|
|||
$action = filter_input( INPUT_POST, 'action' );
|
||||
$messages = [];
|
||||
$complete = false;
|
||||
$data = PledgeMeta\get_pledge_meta();
|
||||
|
||||
if ( 'Submit Pledge' === $action ) {
|
||||
$processed = process_form_new();
|
||||
|
@ -37,6 +38,7 @@ function render_form_new() {
|
|||
}
|
||||
|
||||
ob_start();
|
||||
$readonly = false;
|
||||
require FiveForTheFuture\PATH . 'views/form-pledge-new.php';
|
||||
|
||||
return ob_get_clean();
|
||||
|
@ -48,7 +50,7 @@ function render_form_new() {
|
|||
* @return string|WP_Error String "success" if the form processed correctly. Otherwise WP_Error.
|
||||
*/
|
||||
function process_form_new() {
|
||||
$submission = filter_input_array( INPUT_POST, get_input_filters() );
|
||||
$submission = filter_input_array( INPUT_POST, PledgeMeta\get_input_filters() );
|
||||
|
||||
$has_required = PledgeMeta\has_required_pledge_meta( $submission );
|
||||
|
||||
|
@ -78,7 +80,7 @@ function process_form_new() {
|
|||
return $created;
|
||||
}
|
||||
|
||||
//PledgeMeta\save_pledge_meta( $created, $submission );
|
||||
PledgeMeta\save_pledge_meta( $created, $submission );
|
||||
|
||||
return 'success';
|
||||
}
|
||||
|
@ -93,6 +95,9 @@ function render_form_manage() {
|
|||
$messages = [];
|
||||
$updated = false;
|
||||
|
||||
// @todo Get pledge ID from somewhere.
|
||||
$data = PledgeMeta\get_pledge_meta();
|
||||
|
||||
if ( 'Update Pledge' === $action ) {
|
||||
$processed = process_form_manage();
|
||||
|
||||
|
@ -104,6 +109,7 @@ function render_form_manage() {
|
|||
}
|
||||
|
||||
ob_start();
|
||||
$readonly = false;
|
||||
require FiveForTheFuture\PATH . 'views/form-pledge-manage.php';
|
||||
|
||||
return ob_get_clean();
|
||||
|
@ -115,7 +121,7 @@ function render_form_manage() {
|
|||
* @return string|WP_Error String "success" if the form processed correctly. Otherwise WP_Error.
|
||||
*/
|
||||
function process_form_manage() {
|
||||
$submission = filter_input_array( INPUT_POST, get_input_filters() );
|
||||
$submission = filter_input_array( INPUT_POST, PledgeMeta\get_input_filters() );
|
||||
|
||||
$has_required = PledgeMeta\has_required_pledge_meta( $submission );
|
||||
|
||||
|
@ -133,26 +139,6 @@ function process_form_manage() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function get_input_filters() {
|
||||
return array_merge(
|
||||
// Inputs that correspond to meta values.
|
||||
wp_list_pluck( PledgeMeta\get_pledge_meta_config( 'user_input' ), 'php_filter' ),
|
||||
// Inputs with no corresponding meta value.
|
||||
array(
|
||||
'contributor-wporg-usernames' => [
|
||||
'filter' => FILTER_SANITIZE_STRING,
|
||||
'flags' => FILTER_REQUIRE_ARRAY,
|
||||
],
|
||||
'pledge-agreement' => FILTER_VALIDATE_BOOLEAN,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
|
@ -166,8 +152,10 @@ function has_existing_pledge( $domain, int $current_pledge_id = 0 ) {
|
|||
'post_type' => Pledge\CPT_ID,
|
||||
'post_status' => array( 'pending', 'publish' ),
|
||||
'meta_query' => array(
|
||||
'key' => PledgeMeta\META_PREFIX . 'org-domain',
|
||||
'value' => $domain,
|
||||
array(
|
||||
'key' => PledgeMeta\META_PREFIX . 'org-domain',
|
||||
'value' => $domain,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue