Home  >  Q&A  >  body text

PHP <form method="post"> on multiple carousel slides

Excuse:

I'm making a home page with a carousel. Carousels work great. However, each slide has its own input form. If I try to combine the two forms within a single tag, the page reloads to its original content whenever I change the slide. I believe this is due to the label saving all the inputs together and the form values ​​resetting when the carousel slide index changes.

What do I want to do

I would like to be able to have multiple labels on one page, rather than using a wrapper that causes all selected values ​​to be reset when changing to another slide. Can I use some kind of isset($_POST['form1']) to reference the name of a ?

When I try to use multiple forms, I can't seem to pass any submitted data.

`<div id="myCarousel" class="carousel slide">

            <!-- Indicators -->
            <ol class="carousel-indicators">
                <li class="item1 active"></li>
                <li class="item2"></li>
            </ol>


            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                
                <div class="item active">
                  <!-- 1st input form for carousel slide -->
                  <form method="post" name="form1">
                    <!--- code for 1st carousel -->
                </div>
                  </form>

                <div class="item">
                <!-- 2nd input form on other slide -->
                 <form method="post" name="form2">
                <!-- code for 2nd slide -->
                 </form>
                </div>
             </div>

<!-- submit button that takes data selected from other carousel fields -->
     <form method="post" name="btn-submit">
          <button name="btn">Click here</button>
     </form>`

P粉043432210P粉043432210423 days ago550

reply all(1)I'll reply

  • P粉662361740

    P粉6623617402023-09-16 13:34:59

    You can add inputs to the form to contain any data you like. For example:

    <div class="item">
      <form method="post">
        <input type="hidden" name="formName" value="form2" />
        <!-- code for 2nd slide -->
      </form>
    </div>

    Then in the server side code you just check the value in $_POST["formName"].

    reply
    0
  • Cancelreply