Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

How can I do multiple multiline text boxes in an HTML form input?

I'm trying to have an HTML input form saved into a mySQL database via PHP. It all works, but I need a few multiline input boxes.

I've looked at a lot of previous answers and textarea seems to be the way to go.

However, I can't find if multiple textareas can be put in a single form. I've tried giving them different names and labels, but it doesn't work.

I'm trying to do it all in HTML and PHP as I don't know Jscript.

Are multiple multiline inputs even allowed?

UPDATE

I've managed to write this code, but it changes the multilines into single lines. I see other people have asked this question, so I'll check those answers.

<?php 
 var_dump($_POST);
 echo "<br><br>";
 $singleline1 = '';
 $singleline2 = '';
 $singleline3 = '';
 $multiline1 = '';
 $multiline2 = '';
 $multiline3 = '';
 if(isset($_POST['submit'])):
  echo $_POST['singleline1'] . "<br><br>";
  echo $_POST['singleline2'] . "<br><br>";
  echo $_POST['singleline3'] . "<br><br>";
  echo $_POST['multiline1'] . "<br><br>";
  echo $_POST['multiline2'] . "<br><br>";
  echo $_POST['multiline3'] . "<br><br>";
 endif;
?>
<!DOCTYPE html>
<html>
<head>
 <title>Test for multiple multiline input form</title>
</head>
<body>
 <form action="thispage.php" method="POST" id="myform">
  singleline1: <input type="text" name="singleline1"><br>
  singleline2: <input type="text" name="singleline2"><br>
  singleline3: <input type="text" name="singleline3"><br>
  <textarea name="multiline1">Enter multiline1</textarea><br>
  <textarea name="multiline2">Enter multiline2</textarea><br>
  <textarea name="multiline3">Enter multiline3</textarea><br>
  <input type="submit" name="submit" value="Submit">
 </form>
</body>
</html>

FURTHER UPDATE

I've just realised I should have been using nl2br() around the multiline text I want to echo, as follows:

echo nl2br($_POST['multiline1']) . "<br><br>";
echo nl2br($_POST['multiline2']) . "<br><br>";
echo nl2br($_POST['multiline3']) . "<br><br>";

I suppose this was all quite simple. Anyway, I'll keep the question (with updates) hanging in case anyone finds it useful.

question from:https://stackoverflow.com/questions/66051009/how-can-i-do-multiple-multiline-text-boxes-in-an-html-form-input

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...