php - how to send array in post using codeigniter -
I have sent the arrays in the codeigniter structure as follows:
for (var i = 1; i & lt; = selected; i ++) {& lt; Div style = "float: left; padding-left: 13px; padding-right: 12px; padding-top: 7px; margin-top: 0px;" & Gt; '+ I +' & lt; / Div & gt; & Lt; Input type = "text" name = "unitName []" id = "unit-name '+ i +'" style = "width: 18 9px;" Required /> & Lt; Input type = "text" name = "swan name []" id = "owner name" + i + '"style =" width: 241 pixels; "/ When I try to post it using:
$ owner name = $ this- & gt; Input-> Post ('swami name'); If (is_array (owner name)) {foreach ($ owner name as owner name name) {echo "owner's name is:" $ OwnerName; }} Else {echo "the owner is not the array";} This is my entire controller, with all the posting:
if ($ this- & Gt; form_validation- & gt; run () == incorrect) {$ this-> Load-> See ('newblock'); } And {$ registrar name = $ this- & gt; Input-> Post ('registrarName'); $ Blockname = $ this- & gt; Input-> Post ('blockName'); $ Service type = $ this- & gt; Input-> Post ('service type'); $ Number = $ it- & gt; Input-> Post ('number'); $ Email = $ it- & gt; Input-> Post ('email'); $ Address1 = $ this- & gt; Input-> Post ('address1'); $ Address2 = $ this- & gt; Input-> Post ('address2'); $ Address3 = $ this- & gt; Input-> Post ('address 3 []'); $ City = $ it- & gt; Input-> Post ('city'); $ PostCode = $ this- & gt; Input-> Post ('postcode'); $ BlockUnits = $ this- & gt; Input-> Post ('blockUnits'); Echo print_r ($ _ POST); $ Unitname = $ it- & gt; Input-> Post ('unit-name', TRUE); Unit unit $ [0] per unit '& Lt; Br / & gt; '; If (is_array ($ unitNames)} {foreach ($ unitNames as $ unitNames) {echo "entity name is:" $ UnitName; }} Else {echo "is not the unit array"; } $ Owner name = $ this- & gt; Input-> Post ('Swamyanam', Truth); Echo $ owner name [0]. '& Lt; Br / & gt; '; If (is_array (owner name)) {foreach ($ owner name as owner name name) {echo "owner's name is:" $ OwnerName; }} And {echo "is not the owner array"; } $ Salutations = $ this- & gt; Input-> Post ('Hello', TRUE); Hello Echoes [0] '& Lt; Br / & gt; '; If ($ salutations) {foreach ($ greetings as $ salutation) {echo "Hello:" $ greetings; }} Else {echo "Hello is not array"; } It's displaying "the owner is not an array"; Which indicates that the array is empty, using print_r I found that after the debugging, that array was actually empty, nothing was posted ...
try this
test controller
$ ownerNames = $ this- & gt; Input-> Post ('ownerName'); If (is_array (owner name)) {foreach ($ owner name = owner name as the name of = $ gt; $ k) {echo is "owner's name:". $ K "
"; }} And {echo "is not the owner array"; } See more tests
& Lt; Input type = "text" name = "swear name []" /> & Lt; Input type = "text" name = "swear name []" /> & Lt; Input type = "submit" value = "ownerName" /> & Lt; / Form & gt; // output
is the name of the owner: name1 is the owner's name: name2 is the owner's name: name3
Comments
Post a Comment