title: Warning: substr_count(): Empty substring in
body: <p>I have an issue I cannot figure out.</p>
  
  <p><a href="http://www.realcommissionadvance.com/sign-up-form/" rel="nofollow">http://www.realcommissionadvance.com/sign-up-form/</a></p>
  
  <p>The error is shown if there are two gravity forms on one WP page/post template.</p>
  
  <blockquote>
    <p>Warning: substr_count(): Empty substring in /home/joenygren/public_html/wp-content/plugins/commission-rates-calculator0423/commission_rates_calculator.php on line 176</p>
  </blockquote>
  
  <p>Any ideas?</p>
  
  <pre><code>    &lt;?php
      /**
      * Plugin Name: Commission Rates Calculator
      * Plugin URI: http://ellaking.net
      * Description: Commission Rates Calculator
      * Version: 1.0.1
      * Author: ellaking
      * Author URI: http://ellaking.net
      **/
  
  class Commission_Rates_Calculator{
  
      private $fdate;
  
      function commission_rates_calculator(){
          add_action( 'crc_init', array( &amp;$this, 'crc_enqueue_scripts') );
          add_filter('widget_text', 'do_shortcode');
  
          //add_filter('gform_field_value_fdate', array( &amp;$this, 'populate_fdate') );
          //add_filter('gform_pre_submission', array( &amp;$this, 'add_fdate') );
          add_filter("gform_pre_render", array( &amp;$this, "populate_dropdown"));
  
  //Note: when changing drop down values, we also need to use the gform_admin_pre_render so that the right values are displayed when editing the entry.
  //add_filter("gform_admin_pre_render", array( &amp;$this, "populate_dropdown"));
  
  //Note: this will allow for the labels to be used during the submission process in case values are enabled
  add_filter('gform_pre_submission_filter', array( &amp;$this, 'populate_dropdown'));
  
  
  
          if(is_admin()){
              add_action( 'admin_menu', array( &amp;$this, 'crc_settings_page') );
          }
  
          add_shortcode('commission_rates_calculator', array( &amp;$this, 'crc_show_calculator') );
      }
  
      function crc_settings_page() {
          add_options_page('Commission Rates Calculator', 'Commission Rates Calculator', 'manage_options', 'crc_settings', array( &amp;$this, 'crc_settings'));
      }
  
      function crc_settings(){
          if ( isset( $_POST['save_crc'] ) ) { 
              $new_crc_rate = $old_crc_rate = get_option('crc_rate'); 
              $new_crc_rate = $_POST['crc_rate'];
              $new_crc_anticipated_time = $old_crc_anticipated_time = get_option('crc_anticipated_time'); 
              $new_crc_anticipated_time = $_POST['crc_anticipated_time'];
  
  
              if ( $old_crc_rate != $new_crc_rate ) {
                  update_option( 'crc_rate', $new_crc_rate );
              }
              if ( $old_crc_anticipated_time != $new_crc_anticipated_time ) {
                  update_option( 'crc_anticipated_time', $new_crc_anticipated_time );
              }  
          }
  
          $crc_rate = get_option('crc_rate');
          $crc_anticipated_time = get_option('crc_anticipated_time');
          if(empty($crc_rate)){
              $crc_rate = 0.00075;
          }
          if(empty($crc_anticipated_time)){
              $crc_anticipated_time = 10;
          }
  
          ?&gt;
  
  &lt;script type="text/javascript"&gt;
  jQuery(document).ready(function() {
      jQuery("#crc_form").submit(function(){
          var csc_rate = jQuery("#crc_rate_text").val();
          var crc_anticipated_time = jQuery("#crc_anticipated_time_text").val();
          if(isNaN(csc_rate)){ 
            alert("Please enter a decimal such as 0.00075");
            jQuery("#crc_rate_text").val('');
            jQuery("#crc_rate_text").focus();
            return false;
          }
          if(isNaN(crc_anticipated_time)){ 
            alert("Please enter a anticipated time such as 10");
            jQuery("#crc_anticipated_time_text").val('');
            jQuery("#crc_anticipated_time_text").focus();
            return false;
          }
      });
  });
  
  &lt;/script&gt;
  &lt;div class="wrap"&gt;
      &lt;h2&gt;Commission Rates Calculator Settings&lt;/h2&gt;
      &lt;table class="form-table"&gt;
          &lt;tbody&gt;
              &lt;form method="post" id="crc_form" &gt;
                  &lt;tr valign="top"&gt;
                      &lt;th scope="row"&gt;Commission Rate&lt;/th&gt;
                      &lt;td&gt;
                          &lt;label for="crc_rate"&gt;Please enter a decimal such as 0.00075:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt;
                          &lt;input type="text" name="crc_rate" id="crc_rate_text" value="&lt;?php echo $crc_rate;?&gt;" /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr valign="top"&gt;
                      &lt;th scope="row"&gt;Anticipated Time&lt;/th&gt;
                      &lt;td&gt;
                          &lt;p&gt;
                              &lt;label for="crc_anticipated_time"&gt;Please enter a anticipated time such as 10:&lt;/label&gt;&lt;br /&gt;&lt;br /&gt;
                              &lt;input type="text" name="crc_anticipated_time" id="crc_anticipated_time_text" value="&lt;?php echo $crc_anticipated_time;?&gt;" /&gt;&amp;nbsp;&amp;nbsp;days
                          &lt;/p&gt;                       
                      &lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr valign="top"&gt;
                      &lt;td&gt;
                          &lt;p&gt;
                              &lt;input type="hidden" name="save_crc" value="1" /&gt;
                              &lt;input type="submit" name="Submit" class="button-primary autowidth" value="Save" /&gt;
                          &lt;/p&gt;                       
                      &lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/form&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
          &lt;?php
  
      }
  
      function crc_enqueue_scripts(){
          $crc_rate = get_option('crc_rate'); 
          $crc_anticipated_time = get_option('crc_anticipated_time');
          if(empty($crc_rate)){
              $crc_rate = 0.00075;
          }
          if(empty($crc_anticipated_time)){
              $crc_anticipated_time = 10;
          }
          wp_enqueue_style( 'crc-style', plugin_dir_url( __FILE__ ) . 'css/crc_style.css' );
          wp_enqueue_style( 'crc-jquery-ui-css', plugin_dir_url( __FILE__ ) . 'css/ui-lightness/jquery-ui-datepicker.css' );
          wp_enqueue_script( 'crc-jquery-ui', plugin_dir_url( __FILE__ ) . 'js/jquery-ui-datepicker.min.js', array( 'jquery' ) );
          wp_enqueue_script( 'crc-script', plugin_dir_url( __FILE__ ) . 'crc_script.js', array( 'jquery' ) );
  
          wp_localize_script('crc-script', 'crc_script_options', array('crc_rate' =&gt; $crc_rate, 'crc_anticipated_time' =&gt; $crc_anticipated_time));
      }
  
      function crc_show_calculator(){
          do_action( 'crc_init' );
  
          $mytime = time().rand();
  
          $script = '&lt;script type="text/javascript"&gt;';
          $script .= file_get_contents(plugin_dir_path( __FILE__ ).'crc_script.js');
          $script .= '&lt;/script&gt;';
  
  
          $html = file_get_contents(plugin_dir_path( __FILE__ ).'template.php');
          $html=str_replace('[plugin_dir_url]',plugin_dir_url( __FILE__ ),$html);
  
          $output = $script.$html;
          $output = str_replace('crc_advance_date','crc_advance_date_'.$mytime,$output);
          $output = str_replace('crc_closed_date','crc_closed_date_'.$mytime,$output);
          $output = str_replace('crc_amount','crc_amount_'.$mytime,$output);
          $output = str_replace('crc_pay','crc_pay_'.$mytime,$output);
          $output = str_replace('crc_get_pay','crc_get_pay_'.$mytime,$output);
          $output = str_replace('crc_datediff','crc_datediff_'.$mytime,$output);
  
          return $output;
      }
  
      function populate_dropdown($form){
  
  
  
          $have_crc = false;
          if($form['fields']){
              foreach($form['fields'] as $field){
                  if(substr_count('[commission_rates_calculator]',$field['content']) &gt; 0){
                      $have_crc = true;
                      break;
                  }
              }
              if($have_crc){
                  $output = '&lt;script type="text/javascript"&gt;';
                  foreach($form['fields'] as $field){
                      if($field['label'] == 'crc_advance_date'){
                          $output .= 'var crc__advance_date_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
                      }
                      if($field['label'] == 'crc_closed_date'){
                          $output .= 'var crc__closed_date_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
                      }
                      if($field['label'] == 'crc_amount'){
                          $output .= 'var crc__amount_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
                      }
                      if($field['label'] == 'crc_pay'){
                          $output .= 'var crc__pay_gform_id = "input_'.$form['id'].'_'.$field['id'].'";'."\n";
                      }
                  }
                  $output .= '&lt;/script&gt;';
                  echo $output;
              }
          }
          //print_r($form);
  
          return $form;
      }
  
  
  
  }
  $commission_rates_calculator = new Commission_Rates_Calculator();
  ?&gt;
  </code></pre>