Problems with monetary values in input

0

I have a table of properties in my database, these properties have their field "Value" which is ocmo decimal (19,2).

I then have a system that registers real estate (that goes to the DB) and logically a field to insert the price of the registered property. This field is an input:

<div class="col-md-4">
    <div class="form-group">
        <label class="bold label-color-cinza">Preço</label>
             <input type="text" class="form-control input-sm"
                name="valor"
                value="<?= $imovel->valor ?>"
                placeholder="Preço">
   </div>
</div>

Okay, it's like type="text" because the masks are not working (no mask, nor PHP's number_format), all because the field is a Text, but if I enter a type="number" in the input, the masks also generate a conflict because they do not work in the correct way, besides I want that when giving "Save" (a common button), the value is recorded in this input, which does not happen since like type="text" the masks exclude the numbers and leave only the decimals.

Example (type text):

  • Enter a number: 150,000.00 (with mask or format)
  • Save Button;
  • Input: 150.00 (final value)

#

Example (type number):
- Enter a number: 150.000,00 (with mask or format)
- Button Save;
- Input: 'empty field' (final value)

Did you understand? And like, look. I know it has the type Number and the type Text for input, and the value of the database is decimal, after that, this value still has to be used there in the application site as search value in a real estate filter, if I dare to switch to Varchar in BD, it will even work on the real estate register system, but the filter will not work (it is a business rule that sees if the number that is received is numerical for sequencing the search, it does not come to the case now).

So that's it. I can not fix a mask when typing and saving. I wanted a good answer because I am trying and retaining alternative ways and forms but nothing has happened yet.

Thank you for your attention!

    
asked by anonymous 03.07.2018 / 15:29

0 answers