提交表单后如何使用PHP将多个字符串绑定在一起?

I want several strings to be attached to each other after I submit a form on a different page.

Can someone explain to me what to do?

<html>
<body>    
<form action="" method="post">
  String1: <input type="text" name="inputText"/>
    <br>
    <br>
  String2: <input type="text" name="inputText"/>
    <br>
    <br>
  String3: <input type="text" name="inputText"/>
    <br>
    <br>
  <input type="submit" name="SubmitButton"/>
</form>    
</body>
</html>

<?php    
if(isset($_POST['SubmitButton'])){ //check if form was submitted
$input = $_POST['inputText']; //get input text
echo "Totale string: ".$input;
}    
?>

After submitting, all 3 strings should be attached together.

Like this:

https://i.stack.imgur.com/p9RNh.png

</div>

All your <input> fields look the same: <input type="text" name="inputText"/>.

While the HTML and allows this, it doesn't work as you think. The strings filled in all three input fields are sent to the server as values of the same property (inputText) and they overwrite each other. Only one if them is eventually stored by the interpreter in $_POST['inputText'] where your script can get it from.

However, PHP allows a trick: if the name of the input fields end with [], when the values reach the server the PHP interpreter doesn't store them into the same string variable (later values overwriting previous ones) but in an array.

Change the HTML to look like:

<form action="script2.php" method="post">
  String1: <input type="text" name="inputText[]"/>
    <br>
    <br>
  String2: <input type="text" name="inputText[]"/>
    <br>
    <br>
  String3: <input type="text" name="inputText[]"/>
    <br>
    <br>
  <input type="submit" name="SubmitButton"/>
</form>    

Then, in script2.php you get the values of all three text input named inputText[] into $_POST['inputText'] (which is created as array this way).

Just give to each input a different name

<form action="" method="post">
  String1: <input type="text" name="input1"/>
    <br>
    <br>
  String2: <input type="text" name="input2"/>
    <br>
    <br>
  String3: <input type="text" name="input3"/>
    <br>
    <br>
  <input type="submit" name="SubmitButton"/>
</form>

and in PHP concatenate the inputs...

<?php 
echo "Totale string: ".$_POST['input1']." ".$_POST['input2']." ".$_POST['input3'];
?>

Use this code for your first page:

<html>
<body>    
<form action="script2.php" method="post">
  String1: <input type="text" name="str1"/>
    <br>
    <br>
  String2: <input type="text" name="str2"/>
    <br>
    <br>
  String3: <input type="text" name="str3"/>
    <br>
    <br>
 <input type="submit" name="SubmitButton"/>
</form>    
</body>
</html>

And this code for script2.php:

<?php 

$firstname = $_POST['str1'];
$mi = $_POST['str2'];
$lastname = $_POST['str3'];
$fullname = $firstname . " " . $mi . " " . $lastname;

echo "<br> Totale String : ";
echo $fullname;
echo "<br> First Name : ";
echo $firstname;
echo "<br> Middle Initial : ";
echo $mi;
echo "<br> Last Name : ";
echo $lastname;

?>

ok, I am going to modify this so you can see what one of these would be if it was only one page. I am also going to show you in this example I deal with filtering on a basic level.

     <?php    
        if(!isset($_POST['submit'])){ 
            ?>

     <!DOCTYPE html>
       <html>
        <body>    
       <form action="" method="post">
     String1: <input type="text" name="str1" pattern="[A-Za-z']{13}"/>
          <br>
          <br>
         String2: <input type="text" name="str2" pattern="[A-Za-z']{13}"/>
           <br>
          <br>
         String3: <input type="text" name="str3" pattern="[A-Za-z']{13}"/>
            <br>
             <br>
         <input type="submit" name="submit" value="OK"/>
            </form>    
         </body>
            </html>

      <?php   
                   }else{
      /////load the posts into variables
            $str1=$_POST['str1'];
            $str2=$_POST['str2'];
            $str3=$_POST['str3'];
      ////// then I  filter my apostrophe I let through

          $str1=str_replace("'","&#8217;", $str1);
          $str2=str_replace("'","&#8217;", $str2);
          $str3=str_replace("'","&#8217;", $str3);
      //////now I will echo it but add a space using html entity &nbsp;

            echo $str1."&nbsp;".$str2."&nsp;".$str3;
                }
           ?>

If this is going to be on a web server and a database is envolved, its encouraged to use the PDO method when dealing with user input