Skip to content

Instantly share code, notes, and snippets.

@spivurno
Created June 28, 2022 20:44
Show Gist options
  • Select an option

  • Save spivurno/9544b287e1204b3806ef72db618d8298 to your computer and use it in GitHub Desktop.

Select an option

Save spivurno/9544b287e1204b3806ef72db618d8298 to your computer and use it in GitHub Desktop.
GP Auto Submit MVP
<?php
/**
* GP Auto Submit MVP
*
* 1. Create a form.
* 2. Enable dynamic population on any field you wish to be eligible for auto-submit.
* 3. Create a URL to that form with your dyn pop parameters in place and the "gpas" parameter present.
*/
add_action( 'wp', function() {
if ( ! is_callable( 'rgget' ) || ! rgget( 'gpas' ) ) {
return;
}
$post = get_queried_object();
if ( ! $post || ! is_a( $post, 'WP_Post' ) ) {
return;
}
require_once GFCommon::get_base_path() . '/form_display.php';
GFFormDisplay::parse_forms( $post->post_content, $found_forms, $found_blocks );
$form_id = rgar( array_keys( $found_forms ), 0 );
if ( ! $form_id ) {
return;
}
$form = GFAPI::get_form( $form_id );
if ( ! $form ) {
return;
}
$values = array();
foreach ( $form['fields'] as &$field ) {
// @todo Add support for multi-input fields.
$values[ "input_{$field->id}" ] = RGFormsModel::get_parameter_value( $field->inputName, array(), $field );
}
GFAPI::submit_form( $form_id, $values );
}, 8 /* GF process form on 9 */ );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment