具有相同名称的多个textarea和PHP处理 [英] multiple textarea with same name and PHP treatment
问题描述
我有一个动态表格,可以在其中添加和删除textarea.textareas的名称是MyTextarea []
I have a dynamic form in which i can add and remove textarea. The name of textareas is MyTextarea[]
<textarea style="display:inline;" name="MyTextarea[]"></textarea>
<textarea style="display:inline;" name="MyTextarea[]"></textarea>
所以当我想用PHP处理这个textarea时,我正在做一个:
So when I want to treat this textarea with PHP i'm doing a :
echo $_POST['MyTextarea'];
所以 Array
会显示在屏幕上,到目前为止还可以
So a Array
is display on the screen, up to now it's ok
所以我做一个 print_r($ _ POST ['MyTextarea']);
,我又得到了相同的结果: Array
So I do a print_r($_POST['MyTextarea']);
and I have again the same result : Array
我想知道是否有可能使用 []
来创建多个具有相同名称的textarea来生成数组.
I want to know if it's possible to have many textarea with same name with []
to generate an array.
如果可能的话,我该怎么办,或者我的代码出了什么问题.
If it's possible how can I do, or what's wrong with my code.
谢谢
推荐答案
您正在使用哪种框架,我很确定在某一时刻某些东西会将您数组转换为字符串,也许是对POST变量进行如下处理:
Which kind of framework are you using, I'm quite sure there is something at one point that is casting you're array into a string, maybe something that apply a treatment on POST variable like this:
foreach ($_POST as $key => $value) {
if ($value && !$is_magic_quotes_gpc) {
$_POST["$key"] = addslashes($value);
}
在这种情况下,您必须删除此功能...要确定我在说什么,可以尝试var_dump($ POST [MyTextarea])=>字符串'Array'(length = 5)(应该是数组)
In this case you've to remove this function... To be sure of what I'm talking about, you can try a var_dump($POST[MyTextarea]) =>string 'Array' (length=5) (should be an array)
这篇关于具有相同名称的多个textarea和PHP处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!