• Resolved jakfre

    (@jakfre)


    Hello,

    Is it possible to add a default value for an additional form field?

    I’ve referred to this https://givewp.com/documentation/developers/how-to-create-custom-form-fields/ article and made an additional text field. But I need to add a default value for that text field.

    Ex: I need an additional form field called “Birth City” in the donation form and its default value should be “London”

    add_action( ‘give_fields_after_donation_amount’, function( $collection ) {
    $collection->append(
    give_field( ‘text’, ‘Birth City” )
    ->showInReceipt()
    ->label( __(‘Birth City’) )
    ->value(‘London’)
    ->storeAsDonorMeta()
    ->required()
    ->helpText( __( ‘This is a field used to add your birth city.’ ) )
    );
    });

    I just added this code, but it shows an error. Please advice

    Thanks

Viewing 1 replies (of 1 total)
  • stephanieliy

    (@stephanieliy)

    Hi @jakfre,

    Glad you reached out, I have a snippet that should help get you going:

    add_action( 'give_fields_after_donation_amount', function( $group ) {
        $group->append(
            give_field( 'text', 'birthCty' )
                ->defaultValue('London')
                ->showInReceipt()
                ->label( __( 'Birth Ci‌ty' ))
                ->placeholder('London')
                ->storeAsDonorMeta()
                ->required()
                ->helpText( __( 'This is a field used to add your birth ci‌ty.' ) )
        );
    });

    Hopefully this helps get you going! I’ll go ahead an mark this (and your duplicate ticket) as resolved, but if you have any other questions you can create a new ticket right here and we’ll be happy to help!

Viewing 1 replies (of 1 total)
  • The topic ‘Set a default value to donation form custom field’ is closed to new replies.