Created
September 3, 2026 00:02
-
-
Save rickalday/4ac4e6c690ca4c31e5a24f837297f10c to your computer and use it in GitHub Desktop.
Add a middle name field to a GiveWP donation form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Give\Framework\FieldsAPI\Text; | |
| use Give\Framework\FieldsAPI\Checkbox; | |
| add_action('givewp_donation_form_schema', function($form, $formId) { | |
| //Middle name field | |
| $middlename = Text::make('middlename') | |
| ->showInReceipt() | |
| ->required() | |
| ->storeAsDonorMeta() | |
| ->showInAdmin() | |
| ->receiptLabel(__('Middle name', 'give')) | |
| ->label(__('Middle name', 'give')) | |
| ->emailTag('middleName') | |
| ->showIf('midnamecheck', '=', '0'); | |
| //Checkbox field | |
| $midnamecheck = Checkbox::make('midnamecheck') | |
| ->label(__('I do not have a middle name', 'give')) | |
| ->value('1'); | |
| // Insert after the 'name' fields | |
| $form->insertAfter('name', $middlename); | |
| $form->insertAfter('middlename', $midnamecheck); | |
| }, 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment