get field values from query

While using a front end form, could get values from a query?

Something like this: http://example.com/form?foo_name=bar, so when you click on the link that will take you to the form, the field called foo_name will be fille by default with the value bar.

Related posts

Leave a Reply

2 comments

  1. This is simple to achieve but you will need to edit your template. Just to be clear, this can work on any form but it will not work on the advanced custom fields backend.

    Lets say I have the following URL:

    http://example.com?tid=12&tem=a@b.co.za

    I can get the values from the url using the following PHP and assign it using jQuery:

    jQuery(document).ready(function() {
         jQuery("#text_7").val(decodeURIComponent("<?php $team_id = $_GET['tid']; echo $team; ?>"));
         jQuery("#text_10").val(decodeURIComponent("<?php $email= $_GET['tem']; echo $region;  ?>"));
    });
    
  2. UPDATE:

    This has been solved, I ended up using a function using the acf/load_value filter

    function my_value_( $value, $post_id, $field ) {
        $value = isset( $_GET['foo_name'] ) ? $_GET['foo_name'] : $value;
        return $value;
    }
    add_filter('acf/load_value/key=<field_key>', 'my_value_field', 10, 3);
    

    And for the button/link I used:

    <p class="add-new">
        <a href="<?php echo site_url(); ?>/add-new?foo_name=<?php the_field( 'foo_name' ); ?>">Add New</a>
    </p>