<p>You could do something like this to guard against it:</p>

<pre><code>public function ttr()
{
    $ttr = null;

    if (isset($_POST['tracknum'])) 
        $ttr = $_POST['tracknum']; 
    else if (isset($_GET['tracknum'])
        $ttr = $_GET['tracknum'];

    return $ttr;
}
</code></pre>

CC BY-SA 3.0
2017-07-06T21:25:53.383Z
2017-07-06T21:25:53.383Z
Brad Bell
<blockquote>
  <p>"... why does it work on the original website, but not here?"</p>
</blockquote>

<p><code>Undefined index</code> is a <strong>notice</strong> level PHP error. Which means it's barely important, and can generally be ignored.</p>

<p>This is probably a result of either:</p>

<ul>
<li>Your PHP error level settings are more strict on this machine, and/or</li>
<li>Craft is in <code>devMode</code> on this machine.</li>
</ul>

CC BY-SA 3.0
2017-07-10T13:46:12.237Z
Thanks, it is true, it was only showing up on my development localhost. Good to know!
P. Stucker
CC BY-SA 3.0
2017-07-06T21:01:28.993Z
2017-07-06T21:01:28.993Z
Lindsey D
<p>I'm currently adapting a shipping plugin that has a form for people to submit their tracking number and shipping company.</p>

<p>The template checks the variable, and if it exists, it generates the proper information for the tracking number and company. If the variable doesn't exist, it shows the form.</p>

<p>basically this</p>

<pre><code>if($ttr&lt;&gt;"") {
      All the business logic
} else {
    &lt;form method="get"&gt;
        &lt;input type="text" name="tracknum" /&gt;
        &lt;select name="company" class="smallForm" id="company"&gt;
                (...options...)
        &lt;/select&gt;
        &lt;input type="submit"/&gt;
        &lt;input type="hidden" name="orderAction" value="track"/&gt;
    &lt;/form&gt;
}
</code></pre>

<p>The original check for this this variable looks like this</p>

<pre><code>if (isset($_POST['tracknum'])) 
$ttr = $_POST['tracknum']; 
else $ttr = $_GET['tracknum'];
</code></pre>

<p>So for I put each check in its own variable function, as so</p>

<pre><code>public function ttr()
{
   if (isset($_POST['tracknum'])) 
       $ttr = $_POST['tracknum']; 
   else $ttr = $_GET['tracknum'];
   return $ttr;
}
</code></pre>

<p>and call it thusly</p>

<pre><code>{% if craft.PluginName.ttr|length %}
    All the business Logic
{% else %}
    &lt;form method="get"&gt;
        &lt;input type="text" name="tracknum" /&gt;
        &lt;select name="company" class="smallForm" id="company"&gt;
                (...options...)
        &lt;/select&gt;
        &lt;input type="submit"/&gt;
        &lt;input type="hidden" name="orderAction" value="track"/&gt;
    &lt;/form&gt;
{% endif %}
</code></pre>

<p>This currently returns</p>

<pre><code>Undefined index: tracknum
</code></pre>

<p>Specifically on the line</p>

<pre><code>else $ttr = $_GET['tracknum'];
</code></pre>

<p>Now this makes sense to me, as the form hasn't been submitted, so There should be nothing in the $_POST or $_GET. But if that's the case, why does it work on the original website, but not here?</p>

<p>Thanks!</p>

<plugin-development><plugin-craftcommerce><plugins>
Craft Plugin Variable 'Undefined Index'
# Craft Plugin Variable 'Undefined Index'

(Asked by: username_0 on 2017-07-06)

I'm currently adapting a shipping plugin that has a form for people to submit their tracking number and shipping company.
The template checks the variable, and if it exists, it generates the proper information for the tracking number and company. If the variable doesn't exist, it shows the form.
basically this
if($ttr<>"") {
      All the business logic
} else {
    
        
        
                (...options...)
        
        
        
    
}

The original check for this this variable looks like this
if (isset($_POST['tracknum'])) 
$ttr = $_POST['tracknum']; 
else $ttr = $_GET['tracknum'];

So for I put each check in its own variable function, as so
public function ttr()
{
   if (isset($_POST['tracknum'])) 
       $ttr = $_POST['tracknum']; 
   else $ttr = $_GET['tracknum'];
   return $ttr;
}

and call it thusly
{% if craft.PluginName.ttr|length %}
    All the business Logic
{% else %}
    
        
        
                (...options...)
        
        
        
    
{% endif %}

This currently returns
Undefined index: tracknum

Specifically on the line
else $ttr = $_GET['tracknum'];

Now this makes sense to me, as the form hasn't been submitted, so There should be nothing in the $_POST or $_GET. But if that's the case, why does it work on the original website, but not here?
Thanks!

**Tags:** plugin-development, plugin-craftcommerce, plugins

---

## 2 answers

### Answer by username_1 on 2017-07-06. Score: 1 | Accepted answer

You could do something like this to guard against it:
public function ttr()
{
    $ttr = null;

    if (isset($_POST['tracknum'])) 
        $ttr = $_POST['tracknum']; 
    else if (isset($_GET['tracknum'])
        $ttr = $_GET['tracknum'];

    return $ttr;
}


---

### Answer by username_2 on 2017-07-06. Score: 2

> "... why does it work on the original website, but not here?"

`Undefined index` is a **notice** level PHP error. Which means it's barely important, and can generally be ignored.

This is probably a result of either:

* Your PHP error level settings are more strict on this machine, and/or
* Craft is in `devMode` on this machine.

> **Comments:**
> **username_0**: Thanks, it is true, it was only showing up on my development localhost. Good to know!  

---

