Pass json array to form problem

my coding is this

function PrintMembers(){
			
			var url = '/PrintMList';
			var MDataList = $('#MDataList').val();

					
			var form = $('<form action="' + url + '" method="post" id="search" target="_blank">' +
			  	'@csrf'+
				'<input type="text" name="MDataList" value="' + MDataList + '" />' +									
				'<input type="text" name="Action" value="'+Action+'" />' +				
			
			  '</form>');
			$('body').append(form);
			$("#search").submit();		
		}

in the PrintMList page, the array is empty when i print_r the MDataList in controller as below:

	$var = $request->input('MDataList');
   print_r($var);

PLEASE help. urgent. tq

What type of element is #MDataList? I assume it is a form element because that is what val() works for. But keep in mind that val() is primarily used to get values from input form elements like input, select and textarea elements.

Also know that since the input type for MDataList in your form is a text type, the value is going to be passed as a string, not an array. I can’t really say more until you provide more detail about what type of element #MDataList is pointing to. If you want to pass multiple elements, be sure to string them together in a string, submit it through the form and then split the string using PHP. That or possibly look up how to use square brackets with form input names for creating PHP array elements.

It might also help to tell us what framework you are using since you mention controllers.

laravel

Can you show the text of this rather than an image? Might make it easier to read or copy/paste into an editor.

Is this the source of your #MDataList or what your code snippet produces?

Have you already got a form on the page with ID search?

What happens if you print_r($request->all())?

i try to paste here but it doesnt show when i post the json code here. how do i paste it

shows empty like below:

}

<input type="text"  name="MDataList" id="MDataList" style="visibility:hidden" value="{&quot;1&quot;:{&quot;QrCode&quot;:&quot;&lt;img src=\&quot;..\/storage\/qr\/temp\/748375767cc85b078b2af0e49ee6f398.png\&quot; \/&gt;&quot;,&quot;MCode&quot;:&quot;0001500&quot;,&quot;Name&quot;:&quot;***&quot;,&quot;SCode&quot;:&quot;0351952&quot;,&quot;SName&quot;:&quot;คุณบุญเลิศ  แสงทอง&quot;},&quot;2&quot;:{&quot;QrCode&quot;:&quot;&lt;img src=\&quot;..\/storage\/qr\/temp\/3fb0bda72c886c9af6ecf8280a9eca88.png\&quot; \/&gt;&quot;,&quot;MCode&quot;:&quot;0001132&quot;,&quot;Name&quot;:&quot;GEEE 001&quot;,&quot;SCode&quot;:&quot;0054199&quot;,&quot;SName&quot;:&quot;คุณมะลิ  อรพันธ์&quot;}}" >

can see above json?

no… try putting it inside backticks:

```
JSON here
```

if request->all() is empty, i go back to my original question.
Is there another form with ID search on the page?

no dont have other form with search ID

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.