title: Auto-select fields in Contact form 7 based on referral link
body: <p>I have been using this answer by Aurovrata ( <a href="https://stackoverflow.com/questions/63251548/wordpress-contact-form-7-dynamically-select-dropdown-field-based-on-url">Wordpress Contact Form 7 dynamically select dropdown field based on url</a> )in order to get what I wanted.</p>
  <p>My script is looking like this:</p>
  <pre><code>(function($){
  $(document).ready(function(){
  
    //determine the previous page,
    let page = document.referrer, opt='';
  
  
    switch(true){
      case page.indexOf('service-b')&gt;0:
        opt='serviceb';
        break;
      case page.indexOf('service-c')&gt;0:
        opt='servicec';
        break;
      case page.indexOf('service-a')&gt;0:
        opt='servicea';
        break;
    }
  
    $('select[name=&quot;select-services&quot;]').find('option[value=&quot;'+opt+'&quot;]').prop('selected', 'selected');
  })
  })(jQuery) 
  </code></pre>
  <pre><code>&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  &lt;select name=&quot;select-services&quot;&gt;
   &lt;option value=&quot;&quot;&gt;select a service&lt;/option&gt;
   &lt;option value=&quot;servicea&quot;&gt;Service A&lt;/option&gt;
   &lt;option value=&quot;serviceb&quot;&gt;Service B&lt;/option&gt;
   &lt;option value=&quot;servicec&quot;&gt;Service C&lt;/option&gt;
  &lt;/select&gt; 
  </code></pre>
  <p>The result is that the right service is selected for one second and after that is going back to the default. Any idea what I'm doing wrong?</p>
  <p>PS: In order to get it done, I have added this script in function.php to prevent the CF7 resetting the form:</p>
  <pre><code>add_action('wpcf7_enqueue_scripts', 'prefix_fix_form_reset');
  
  function prefix_fix_form_reset() {
      $wpcf7 = array();
      wp_localize_script( 'contact-form-7', 'wpcf7', $wpcf7 );
  }
  </code></pre>