Problem with an HTML / JavaScript / PHP form

1

I have a problem with an HTML / JavaScript form that is then processed and validated with PHP:

On my site there is an HTML form, and the first label is a selection of multiple options, however looking with a bit of JavaScript I am trying to make when the user selects an option to change the value automatically from the field below.

The problem is that when I try to use PHP to validate if the field is empty, because although the field automatically changes to the value set in the options selection (Option 1) if I delete the content that was automatically set when selecting one of the options of the select PHP continue taking into account the value that is placed in the field automatically of the selection of options and not the input of the user.

The option selector is a reference for the user to know what format to use to shorten a page URL for Minecraft: PE servers.

Example: An option of the option selection says minecraftpocket-servers.com, when you select the field below (which is a text input) it will change to the value="" that I defined it to be link . The user should simply enter the number that follows, for example minecraftpocket-servers.com/server/38304, that's all.

I enclose the HTML, JavaScript and PHP code:

HTML :

<form class="form-horizontal" role="form" id="stepOneForm" name="createform" action="" method="post">
                            <p>URL Details</p><small>Complete required fields</small>
                            <div id="errors"></div>
                            <div class="form-group">
                                <label for="inputIp" class="col-lg-2 control-label">Voting Site</label>
                                <div class="col-lg-10">
                                <label for="select" class="col-lg-2 control-label"></label>
      <div class="col-lg-2">
        <select name="select" class="form-control" id="select">
          <option value="minecraftpocket-servers.com/server/">minecraftpocket-servers.com</option>
          <option value="minecraftpeservers.org/server/">minecraftpeservers.org</option>
          <option value="minecraftlist.org/pe-server/">minecraftlist.org/pe-servers</option>
          <option value="minecraft-pe-servers.com/servers/">minecraft-pe-servers.com</option>
          <option value="minecrafthub.com/pe-server/">minecrafthub.com/pe/servers</option>
         <option value="topg.org/server-">topg.org/minecraft-pe-servers/</option>
         <option value="minecraftpocketserverlist.eu/vote-">minecraftpocketserverlist.eu/</option>
        <option value="mcpeindex.com/server.php?id=">mcpeindex.com/</option>
        </select>
    </div><br>
                                    <input type="text" class="form-control" name="longlink" id="inputIP" maxlength="150" placeholder="Path" required="">
                                    <p class="help-block">Enter the numbers or characters that follow of the mcpe voting site to access your server voting page</p>
</form>

JavaScript :

<script type="text/javascript">
$(function() { 
    $('#select').change(function() {
         $('#inputIP').val($(this).val());
    }).change();
});   
</script>

PHP :     

if(isset($_POST['longlink']))
{
echo ("Set!");

}
else {

echo ("Not set!");
exit;

}
?>

I hope I have been as clear as possible and also a prompt resolution of my problem.

    
asked by Alfonso Pineda 03.04.2017 в 23:31
source

1 answer

3

One way to correct the error is to change your HTML code and add the attribute explicitly in the input:

<input type="text" class="form-control" name="longlink" id="inputIP" maxlength="150" placeholder="Path" required="">

Also change the JavaScript a bit so as not to generate conflicts with other libraries:

jQuery(function($){
  $('#select').change(function(){
    $('#inputIP').val(this.value);
  }).change();
});
    
answered by 04.04.2017 в 01:44