Create input with fixed value

0

I want to create a input to insert mobile contacts.

<h5>
  <strong>Contato</strong>
</h5>
<input type="text" id="Contato" name="Contato" value="351" 
       style="width:150px" required />

I want the 351 code not to delete the user, but it is possible to add the customer number, for example, 35191234455xx. When entering in the table, you must enter the area code and the number.

    
asked by anonymous 18.12.2018 / 11:37

2 answers

1

Since it is a fixed number that should not be changed, put it out of the input, where the user will just insert the rest of the numbers in this input, something like this:

351 <input type="tel" name="telemovel">

In the backend (PHP) you check if the user has entered the number correctly and concatenates the "351" to the number:

$telemovel = $_POST['telemovel'];
if(!empty($telemovel)) $telemovel = '351'.$telemovel;

In this way, if the value of $telemovel is empty, nothing will be inserted in the table column where you want to save that number.

    
18.12.2018 / 14:49
2

Well, I do not know if this is the best way to do it. I created a div by simulating input , with input readonly inside and with other input text on the side so you can edit the value after 351.

<style>.read {
  border: none;
  width: 20px !important;
  margin-left: 5px;
}

.ajuste{
  width: 77.5% !important;
}

div.input {
  width: 155px;
  height: 20px;
  border: 0.3px solid gray;
} </style>
   
<div class="input">
  <input type="text" readonly id="Contato" class="read" name="Contato" value="351" required>
  <input class="read ajuste">
</div>
    
18.12.2018 / 11:40