Send form data to a URL

Asked

Viewed 546 times

1

I know html, but I’m no expert. I created a website for my hostel based on a template I purchased on themeforrest and it has a form that receives data (as input, output, adults, etc)

the form is as follows:

<!--Book Section-->
<section class="book-section">
    <div class="auto-container">

        <div class="row clearfix">

            <!--Title Column-->
            <div class="title-column col-lg-2 col-md-12 col-sm-12 col-xs-12">
                <div class="bg-layer"></div>
                <!--Inner Box-->
                <div class="inner-box">
                    <h2>RESERVE</h2>
                    <div class="text">Melhor Preço Garantido</div>
                    <!--Arrow Box-->
                    <div class="arrow-box"><span class="icon fa fa-angle-right"></span></div>
                </div>
            </div>

            <!--Form Column-->
            <div class="form-column col-lg-10 col-md-12 col-sm-12 col-xs-12">
                <div class="inner-box">
                    <form method="post" action="contact.html">
                        <div class="clearfix">
                            <div class="column col-md-9 col-sm-12 col-xs-12">
                                <div class="clearfix">


                                    <div class="form-group col-md-3 col-sm-6 col-xs-12">
                                        <div class="group-inner">
                                            <label>Check In</label>
                                            <input type="date" name="in" value="" placeholder="Entrada" required>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-3 col-sm-12 col-xs-12">
                                        <div class="group-inner">
                                            <label>Check Out</label>
                                            <input type="date" name="out" value="" placeholder="Saída" required>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-3 col-sm-12 col-xs-12">
                                        <div class="group-inner">
                                            <label>Adultos</label>
                                            <input type="number" name="adultos" value="" placeholder="Adultos" min="1" max="4" required>
                                        </div>
                                    </div>

                                    <div class="form-group col-md-3 col-sm-12 col-xs-12">
                                        <div class="group-inner">
                                            <label>Crianças</label>
                                            <input type="number" name="child" value="" placeholder="Crianças" min="0" max="3">
                                        </div>
                                    </div>



                                </div>
                            </div>

                            <!--Avalability Column-->
                            <div class="avalability-column col-md-3 col-sm-12 col-xs-12">
                                <a target="_blank" href="https://hbook.hsystem.com.br/Booking?companyId=593ec639c19a3b40b852aaec">
                                <button type="submit">
                                    <span class="big-txt">Reservar agora</span>
                                    <span class="small-text">Checar disponibilidade</span>
                                </button></a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>


    </div>
</section>
<!--End Book Section-->

I am working with an online booking company and I need to pass the data of this form to the URL of this company’s website. For example:

https://booking/booking? companyId=COMPANY_ID&Adults=2&checkin=2017-09-07&checkout=2017-09-10

The companyId is fixed, and is not passed by the form. But the checkin and checkout, for example, they would need to receive different values from that form for each different customer.

What is the best way to proceed? I am currently redirecting directly to the online booking URL without passing the parameters.

2 answers

4


In your HTML the input's has to have the attributes name as the page that will receive the data awaits. The companyId should be in a input with type="hidden".

The page will receive the parameters by the method get, then you can use this form as an example and adapt to your code:

<form action="https://reservas/booking" method="get">
    <input type="hidden" name="companyId" value="COMPANY_ID">
    Adultos: <select name="adults">
        <option value="1">1</option>        
        <option value="2">2</option>        
    </select>
    Check-in: <input type="date" name="checkin">
    Check-out <input type="date" name="checkout">
    <input type="submit" value="Consultar Disponibilidade">
</form>

Replace the COMPANY_ID in the code by your ID.

  • 1

    Thank you very much!

1

Use the

<form method=get action=pagina.php(sem o resto do link)>

And create inputs with name = fieldname Example:

<input name=ADULT type=text>
  • Thank you very much!

  • @Fernando Glad you liked the answers! But the best way to thank those who helped you is to mark "accept" the best answer and vote for all who helped you. This way you make sure that whoever wrote the answer gets something in return, as well as making the site cleaner and more useful for everyone. Adding a new answer like this (which is not an answer to the question and should be removed) makes the site more confusing and can get in the way.

Browser other questions tagged

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