• Resolved Christopher

    (@cjsheps)


    Hi

    Is it possible to pass form field input data to the submit button before its clicked?

    I’ve looked at the documentation and have looked at the functions. I’m able to add static attributes but I have no idea how to pass the Date field input to the button attribute.

    function filter_submit_button_attributes( $attributes, $form, $args ) {
     //   $attributes['class'] .= ' button';
    	  $attributes['data-bookingform-redirect'] .= 'true';
    	  $attributes['data-hotel-id'] .= 'largehotel';
    	
        return $attributes;
    }
    add_filter( 'af/form/button_attributes/key=form_63e8ce3cdc102', 'filter_submit_button_attributes', 10, 3 );

    How can i pass the form field input to an attribute? Ive tried using

        $attributes['data-departure'] .= 'af_get_field( "$field_63e8ce9bb2cb9" )';
    	$attributes['data-arrival'] .= 'af_get_field( "$field_63e8ce6ffe3fb ")';

    But this only prints it as a static attribute

Viewing 1 replies (of 1 total)
  • Plugin Author philkurth

    (@philkurth)

    Hi @cjsheps,

    The af_get_field() function accesses data from the submission after the form is submitted back to the server. The af/form/button_attributes affects the form on render. So, it isn’t possible to use the two together.

    I’m assuming you need the data on the form button for some JavaScript to consume — is that correct? If so, your only real option is to use JavaScript to get the field values from the form and add them to the button at an appropriate moment. When will depend on when the JS code that depends on these attributes is firing. If it reads the data on render, it won’t be doable. If it reads it on submit, you could look at using the jQuery submit() method OR you could use the jQuery change() method to update the button when the specific field is updated.

    Cheers,
    Phil

Viewing 1 replies (of 1 total)
  • The topic ‘Pass field input to button attribute’ is closed to new replies.