0 Users appreciate this thread.
[HTML/PHP] Form Submission Echoing
This topic is closed, so you can not post a comment.
Back to forum: Programming (Python, Java, Delphi/Pascal, C, VB, etc)
New registered users today: 7
Newest registered user: ElegantVulpes
Read before continuing with tutorial
Depending on what you are going to use this for, you may need to set a character limit or disable programming languages where the text is being echoed, I'm not responsible for any damage on your webserver/server, talking about servers, depending on the (we
The intro
In this tutorial, I will show and explain how to echo the text which you've submitted via form (which would be the text box).
So let's cover the first part of the form...
<form name="output" action="" method="post">
This uses the form tag, I've set the form name to "output" (keep a note of it for later if you want to show the text after), the reason why the action flag is not set to go to a page because I want it to post the data on the same page, as for the method, I've made it POST so it posts that content, GET is something else that we may soon have a look at.
Creation of text fields
We're now going to the text field part which you can have a load of fun with.
<input type="text" name="text" placeholder="Enter text here" required>
This uses the input tag, the type is text so any type of text can be entered making it a text box, the name is "text" (you can set it to what ever you want), also keep a note of this, I've set a placeholder tag which basically places text in the text box but when pressed, it disappears, useful for hints or examples, also I did add "required" at the end, what this does is give you a minor warning popup coming from the text box saying that the text box must be filled in.
Push the button!
The button part already?, well here is the code...
<input type="submit" name="submit" value="Echo">
So again, this uses a input tag, the input type is submit which makes it a submission button, the name of it is "submit" (you can change it, keep a note of it if you're going to do the extra), the value, which is the text which appears on the button is "Echo", you can change that to what ever you want as well.
Echo echo echo...
Now for echoing after submission...
<?php echo $text ?>
Ah, some fresh PHP, the echo command echos (stating the obvious) text or other parameters, remember the text box name?, well you'll need to enter the name with $ in front of it, after submission, it should echo your text which you've entered in the text box.
[hr /]
[EXTRA] Hide and show
An extra I see, this is going to be an interesting one...
<?php
$DisplayForm = True;
if(isset($_POST['submit'])){
$DisplayForm = False;
}
if ($DisplayForm) {
?>
Echoed text goes here
<?php
}
?>
The string "$DisplayForm = True;" says that it should show up first, "if(isset($_POST['submit'])){" is saying if the page gets a POST request then... "$DisplayForm = False;" hide that content "} if ($DisplayForm) { ?>" is incomplete without } so you place whatever content you want to show up before submission and then "}" will close it up, to hide the content at first after submission, you'll have to change the first line "$DisplayForm = True;" to '$DisplayForm = False;', for the third line, just do the opposite so "False" becomes "True".
DEMO: http://caftp.pcsat.tv/extras/tools/echoer
2014-03-10 16:34:57