How to unify all Forms?

Asked

Viewed 36 times

0

I’m developing a basic engine lubrication validation system from my father’s workshop, but I’ve come up with a problem I can’t seem to solve.

the code performs the following function:

  • Takes all engines through the foreach in the database with lubrication "NOT OK".

  • Then lists engines by creating a checkbox for each engine NOT OK.

The problem is that when LISTING engines, form’s are created for each of the engines and I would like to leave everything within A SINGLE FORM, listing all engines with delayed lubrication.

Code:

                    foreach ($lubrificado as $value)
                {
                  if($value['nome_trp'] == "T01")
                  {
                    if($value['lubrificado'] == "N")
                    {
                      //print_r($lubrificado);
                      echo '<p class="has-text-centered"> Redutor com RG:<strong><big> '.$value['rgmotor'].'.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value='.$value['rgmotor'].'>Lubrificado ?</label></form>';
                    }
                  }
                }
              }

Upshot:

       <div class="column">
          <p class="has-text-centered"> Redutor com RG:<strong><big> 19.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=19>Lubrificado ?</label></form><p class="has-text-centered"> Redutor com RG:<strong><big> 20.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=20>Lubrificado ?</label></form><p class="has-text-centered"> Redutor com RG:<strong><big> 21.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=21>Lubrificado ?</label></form><p class="has-text-centered"> Redutor com RG:<strong><big> 24.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=24>Lubrificado ?</label></form><p class="has-text-centered"> Redutor com RG:<strong><big> 25.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=25>Lubrificado ?</label></form><p class="has-text-centered"> Redutor com RG:<strong><big> 26.</strong></big></p><form action"lubrificarmotor.php" method="POST"><label class="has-text-right" class="checkbox"><input type="checkbox" value=26>Lubrificado ?</label></form>            </div>

I got something like this:

?>
                <form action="lubrificarmotores.php" method="POST">
                <?php
                foreach ($lubrificado as $value)
                {
                  if($value['nome_trp'] == "T01")
                  {
                    if($value['lubrificado'] == "N")
                    {
                      ?>
                        <p class="has-text-centered"> Redutor com RG:<strong><big> <?php echo ($value['rgmotor']) ?></strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="<?php echo($value['rgmotor'])?>">Lubrificado ?</label>
                    <?php
                    }
                  }
                }
                ?>
                <br>
                <input class="button is-danger is-default" type="submit" name="Salvar" value = "Enviar">
                </form>
                <?php
              }
            }
          ?>

Upshot:

                                  <form action="lubrificarmotores.php" method="POST">
                                            <p class="has-text-centered"> Redutor com RG:<strong><big> 19</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="19">Lubrificado ?</label>
                                                <p class="has-text-centered"> Redutor com RG:<strong><big> 20</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="20">Lubrificado ?</label>
                                                <p class="has-text-centered"> Redutor com RG:<strong><big> 21</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="21">Lubrificado ?</label>
                                                <p class="has-text-centered"> Redutor com RG:<strong><big> 24</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="24">Lubrificado ?</label>
                                                <p class="has-text-centered"> Redutor com RG:<strong><big> 25</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="25">Lubrificado ?</label>
                                                <p class="has-text-centered"> Redutor com RG:<strong><big> 26</strong></big></p>
                        <label class="has-text-right" class="checkbox"><input type="checkbox" value="26">Lubrificado ?</label>
                                        <br>
                <input class="button is-danger is-default" type="submit" name="Salvar" value = "Enviar">
                </form>

I can leave it this way ?

  • Welcome to the Matheus site! I ask you to transfer the image content of your question (copy the code) and replace it.

  • Edited the post.

  • If you want a form only, why put a <form> </form> for each line in the field?

  • It generates a form for each line because of foreach.

  • So. You have a loop of repetition that generates multiple forms; you want just one; what’s the first thing that comes to your mind?

  • @Matheuslucas yes, I saw that it generates one for each line, my question is pq pos on foreach if you want a form only for all lines.

  • 2

    @Matheuslucas looks there, thought a little and advanced the result, that’s a good sign. But I could have put it in the field of solutions, since it worked, not the question. About "being able to leave it like this", it depends. That’s what I wanted?

  • Bacco, really it was this way of wanted !. thanks for making me think a little kkk

  • @Matheuslucas I would suggest you remove complete code from your question solution and put in the answer field, and mark as correct, so it gets the question and answer pair straight..

Show 4 more comments

1 answer

-2


leaves the < form > tag outside the "for" repeat structure, and inside the "for" let what you want to display.

Browser other questions tagged

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