php在复选框上添加一个文本框不会发布

I have code that adds input text when the box is checked and it shows up but getting the value from the code does not work. Here is my code:

<input name=ship[] type=checkbox value=example id=Ex>Application Model Example
<span id='Location'>& nbsp;</span>

var checkbox = document.getElementById('Ex');
checkbox.addEventListener('change', function () {
if (document.getElementById('modelType')) {
    document.getElementById('modelType').remove();
} else {
      var input = document.createElement("input");
      input.name = 'modelType';
      input.id = 'modelType';
      input.type = 'text';
      input.placeholder = 'Model Type';
      input.required;
      document.body.appendChild(input);
      var foo = document.getElementById('Location');
      foo.appendChild(input);
}
});

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
echo "Model Type is $modelType";
}

The text input only appears after I click the checkbox which is exactly what I want, but when I go to get the value in the text input in POST is never appears? Also it would be nice if the text input was required, but input.required; does not work (that was just a guess)

You are not using PHP properly. It has not for a LONG time now auto-created variables for you based on form-inputs. This is a GOOD thing. register_globals is dead, gone, and gloriously so.

Your code should be

echo "Model Type is {$_POST['modelType']}";