Automatic number for form

Asked

Viewed 92 times

0

I wanted to put an automatic number after filling out a form or imagine that I will fill out my form that has to say Reservation No 1/2018 after when someone else is filling out another form that has to say Reservation No 2/2018. I don’t know if I understand.Thank you to everyone who can help me.

My html:

Reservation No/2018

    <tr>
        <td>
            Dia:
        </td>
        <td>
            <input name="dia" type="date"  required />
        </td>
    </tr>

    <tr>
        <td>
            Pessoas:
        </td>
            <td>
             <input name="pessoas"  type="number"  MAX="14" required />
            </td>
    </tr>

    <tr>
        <td>
            Hora:
        </td>
            <td>
            <select name="hora"type="text" required >
                <option value="0"></option>
                <option value="12:30">12:30</option>
                <option value="13:00">13:00</option>
                <option value="13:30">13:30</option>
                <option value="14:00">14:00</option>
                <option value="14:30">14:30</option>
                <option value="15:00">15:00</option>
                <option value="15:30">15:30</option>
                <option value="18:30">18:30</option>
                <option value="19:00">19:00</option>
                <option value="19:30">19:30</option>
                <option value="20:00">20:00</option>
                <option value="20:30">20:30</option>
                <option value="21:00">21:00</option>
                <option value="21:30">21:30</option>
                <option value="22:00">22:00</option>
                <option value="22:30">22:30</option>
                <option value="23:00">23:00</option>


            </select>
            </td>
    </tr>


    <tr>
        <td>
            Nome:
        </td>
            <td>
                <input name="nome" type="text" placeholder="Nome Completo" required />
            </td>
    </tr>



    <tr>
        <td>
            Numero:
        </td>
            <td>
                <input name="numero" type="number" required" />
            </td>
    </tr>


    <tr>
        <td>
            E-mail:
        </td>
            <td>
                 <input name= "email" type="text" required />
            </td>
    </tr>


                        <tr>
        <td>
        Mesa:
        </td>
            <td>
                <input name="mesa" type="Number" value="Reservar" max="11" required />
            </td>
    </tr>

    <tr>
        <td>    
        </td>
            <td>
            <div class="butoesdelembrar">
              <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px font-size:60;"> Receber informação de eventos futuros?<br>
            <input type="checkbox" checked="checked" name="remember" style="margin-bottom:15px"> Promoções e atualizações deste restaurante<br>

  • I think you need to store every record in the database so you have a sequential number of records. In plain html, I don’t think you can, because every time you load the page, it goes back to the starting number.

  • then what if I put the visible id or when people make the reservation will be able to see that it is the id 1 realizes?

  • You don’t need to make the ID visible, only if you want... the problem with the code is that every record you make, the ID will always be the same. You’re storing it in a database?

  • not yet but a friend of mine told me that this could do with javascpirt but I searched and did not find

  • Honestly, I’m almost sure you can’t do this in Javascript, because you have no way to save the value...

  • I have to use php then?

  • Yeah, it’s good... you log in to the comic book every time a registration is created, and from there you have the ID. If you want, create another field that says "idregisto" so you can handle the ID and increase the i/2018 (1/2018,2/2018,3/2018...)

  • 2

    @Sintra, the Javascript runs in the user’s browser, so you won’t have to control the numerical sequence for all users, each user will start at "1". For this to work, you need to centralize the code, and it has to be done on the side server, no matter the language. Imagine you are number "10", the next for sure will be "11", but what if another user, in another browser try to save the form first and already used "11"? Understand why the server needs to control this?

  • But it is possible to do this with Javascript + Firebase, but maybe it’s easier with PHP + SQL. Take a look and see which one you prefer

  • kk thanks to everyone who gave me tips.

Show 5 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.