2014-06-05 68 views
0

PHP文本区的内容:打印工作不

if(isset($_POST['submit_'])) 
{ 
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor'])) 
    { 
     echo 'hello'; 
     $msg = $_POST['textEditor']; 
     echo ($msg); 
    } 
} 

HTML:

<input type="submit" name="submit_" value="Add" /> 
<textarea name="textEditor" rows="20" cols="60" > </textarea> 

我想打印时,点击提交按钮文本区域的内容。但即使textarea非空,它也不会打印任何内容。

对于测试,我打印'你好',但它仍然打印什么都不是第二'如果'陈述不满意我不明白为什么第二个'if'陈述失败

如果我删除第二个if语句,然后我得到一个错误:

Notice: Undefined index: textEditor in... 
+0

好像你的textarea的形式之外?为什么会在提交按钮后?也许你也关闭了真实页面上的按钮后的表单。 –

+0

请从 –

回答

1

看来你texteditor外在形式的,你需要尝试像

<?php 
if(isset($_POST['submit_'])) 
{ 
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor'])) 
    { 
     echo 'hello'; 
     $msg = $_POST['textEditor']; 
     echo ($msg); 
    } 
} 
?> 
<form method="post"> 
<textarea name="textEditor" rows="20" cols="60" > </textarea> 
<input type="submit" name="submit_" value="Add" /> 
</form> 

如果形式设置已经尝试检查表格method="post"print_r($_POST);在php代码

0

可能是调试代码将帮助你。 作为把这个代码下如果(isset($ POST [ '提交'])){线

echo "<pre>"; 
print_r($_POST); 
echo "</pre>"; 

希望这会有所帮助。

1

试试这个:

<html> 
<?php 
    if(isset($_POST['submit_'])) 
{ 
    if(isset($_POST['textEditor']) && !empty($_POST['textEditor'])) 
    { 
     echo 'hello'; 
     $msg = $_POST['textEditor']; 
     echo ($msg); 
    } 
} 
?> 
<head> 



</head> 
<body> 
    <form name="myForm" method="post"> 

     <textarea name="textEditor" rows="20" cols="60" > </textarea> 
     <input type="submit" name="submit_" value="Add" /> 
    </form> 
</body> 
</html> 

希望它可以帮助

+0

显示您的完整html代码谢谢!它的作品,我已经投了票! :) –