Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More
( 7 months ago )

how to access array form position dynamically in html/php form?

General Tech Learning Aids/Tools
Max. 2000 characters
Replies

usr_profile.png
Amie Khalifa

User

( 7 months ago )

I´m not sure I understand the question correctly, but are you looking for something like:

<input type="hidden" name="usr[{index_in_array}]" value="abobora">
<input type="hidden" name="iditem[{index_in_array}]" value="{$homeList[i].IDItem}">

Edit: You are not closing the <form> correctly and that´s why you can´t rely on the index values that get sent in:

        <td><form action="updatecart.php"  method="POST">
            <input type="hidden" name="usr[]" value="abobora">
            <input type="hidden" name="iditem[]" value="{$homeList[i].IDItem}">
            <input type="hidden" name="qta" value="1">
            <input type="hidden" name="index" value="1">
            <input type="image" name="submit" src="../images/carro.png" width="52" height="52">
          </form>            // added
        </td>

usr_profile.png
James Watson

User

( 7 months ago )

 

I am doing a little learning on php and and html using smarty to aid it. I am trying to build a very simple shop-alike list with a cart image that when it is clicked, it is supposed to return via form the info I want from that item, but I am failing to get the index of the items right....

This is the code relative to the loop inside the tlp (it is a HTML internally used by smarty):

{section name=i loop=$homeList}
     <div class="homemenu" align="right">
        <table class="menhome" border="0">
            <tr>
            <td width="102"><img src="{$homeList[i].img}"/></td>
            <td width="150">{$homeList[i].Nome} </td>
            <td width="350">{$homeList[i].Descricao}</td>
            <td width="80">{$homeList[i].Preco} €</td>
            <td width="80">{$homeList[i].Disponiblidade}</td>
            <td><form action="updatecart.php"  method="POST">
                <input type="hidden" name="usr[]" value="abobora">
                <input type="hidden" name="iditem[]" value="{$homeList[i].IDItem}">
                <input type="hidden" name="qta" value="1">
                <input type="hidden" name="index" value="1">
                <input type="image" name="submit" src="../images/carro.png" width="52" height="52"> 
            </td>
            </tr>
        </table>
    </div>
{/section}

and this is the code relative to the "experimental" php update:

require_once("functions.php");
var_dump($_POST);

and this is a sample var_dump output:

array
'usr' => 
    array
      0 => string 'abobora' (length=7)
      1 => string 'abobora' (length=7)
      2 => string 'abobora' (length=7)
      3 => string 'abobora' (
			
        

what's your interest