1

I have a list in html written like this:

<form action="check.php" style="display:none" method="post">
   <h1 class="text-center">your items are</h1>
   <ul id="riepilogo" name="riepilogo">
       <br/>
       <li name="">first item</li>
       <li name="">second item</li>
       <li name="">third item</li>
       ...
   </ul>

   <input type="submit" value="Pay" id="pay"/>
</form>

this code is written in a html page, now problem is that I don't know how to display all of this items in a new page using php. I think that maybe i need to set the same name to all the items in the list and then store them in a php array. I really don't know! Maybe it can't be don with php, I really don't know. Thanks for the help Daniele

  • you have invalid html - `
      ` and `

      ` 99% of the time shouldn't be wrapped in a `

    `
    – treyBake Jan 02 '19 at 14:10
  • You can check this question answer [Pass form data to another page with php](https://stackoverflow.com/questions/15236733/pass-form-data-to-another-page-with-php) – Ahmed Bermawy Jan 02 '19 at 14:13
  • 3
    @treyBake Using `
      ` inside `
    ` is technically totally valid, so don't claim otherwise. It won't post the data, but that does not make it invalid html.
    – Peter B Jan 02 '19 at 14:14
  • @PeterB ah yes, sorry I think I've used the wrong terminology! What I mean to say, it's not correct *semantically* - not invalid HTML – treyBake Jan 02 '19 at 14:16
  • @PeterB or maybe I've just got an impression in my head that it's 100% incorrect to do xD – treyBake Jan 02 '19 at 14:16
  • hi @AhmedAlBermawy i've already seen that post but the problem is that every input type as a different name that is used to pass the informations. I need to transform it uniquely. Here in stac overflow there's a type of chat where i can explain you my problem? Seriusly, i don't know what to do – DanieleCicca Jan 02 '19 at 14:26
  • @DanieleCicca can you show what you want to achieve with your code? – JohnnyB1988 Jan 02 '19 at 14:28
  • @DanieleCicca , there is a chat room for php you can join it https://chat.stackoverflow.com/rooms/11/php – Ahmed Bermawy Jan 02 '19 at 14:33
  • when the user clicks on the sublit button a new pag appears with the same list but this time this list must be written by php. – DanieleCicca Jan 02 '19 at 14:34

1 Answers1

0

You need to put name to each li with [] to submit it as an array

     <form action="check.php" style="display:none" method="post">
   <h1 class="text-center">your items are</h1>

   <ul id="riepilogo" name="riepilogo">
       <br/>
       <li >first item <input type='hidden' name='riepilogo[]' value='first item'/></li>
       <li >second item <input type='hidden' name='riepilogo[]' value='second item'/></li>
       <li >third item <input type='hidden' name='riepilogo[]' value='third item'/></li>
       ...
   </ul>

   <input type="submit" value="Pay" id="pay"/>
</form>

When submitted, you'll get an array in $_POST named riepilogo with those value.

HamzaNig
  • 1,019
  • 1
  • 10
  • 33