Would I use Javascript to code this?

I want to create a form with one text field.

When you type in something to the text field and click “submit” it then shows you another plain text page with <body> and </body> prefacing and then appended to the end of the text.

Is that clear? Basically just want to have the output include additional text. Thanks

Form submission is not something that requires javascript. Some developers may use it for that (ie Ajax) to give users a smoother browsing experience in certain cases.

Sent from my XT316 using Tapatalk 2

Ok, I think isee what you are doing now. Having a form add text to a web page can be achieved with javascript however I don’t see the point unless this is a purely academic exercise. Usually forms are used to submit data to a web server which then records that information in some kind of database. For the latter javascript would not be essential.

Sent from my XT316 using Tapatalk 2

It sounds to me that this is a job for a server-based language, such as PHP (if I am understanding you correctly).

You would normally specify where you want the form data to be sent in the action attribute of your <form> tag.


<form action="index.php" method="post">
  <label for="name">Enter your name:</label>
  <input Type="text" name="name" id="name "/><br>
  <input type="submit" />

Then in index.php you can access whatever data has been sent.


  $name = $_POST['name'];
  echo "Hello, " . $name;

Is this the kind of thing you are after?

I’m just trying to figure how to add text to an output submission.

You put in your Name in a form, you click a Button, and then it outputs it with that NAME but with additional text.


I have a LABEL and an INPUT.

The Label says “Insert Name.” I type in my name in the INPUT and it is given the variable “MYNAME”.

I click Submit

It spits out: This is “MYNAME”

Where “This is” is the extra text. I want to biuld something like this, and i want to replace “This is” with html tags… that way it makes it easier to populate a table.

Actually, think I found my solution here: http://www.w3schools.com/php/php_forms.asp

Erm, did you actually read my answer above? :slight_smile:
This is exactly what I gave you.

Also, I’d be a bit careful what you learn from the W3Schools site.
It’s ok as a quick reference, but not very good as a place to learn much beyond the basics.
This site explains it in more detail: http://www.w3fools.com/

Thank you!

By the way, any tips on how to make sure a php form can be encrypted or secure? So no one can inject any code?

Sanitize your user’s input before doing anything with it and use PDO if doing anything with databases.
Other than that if you have a concrete question, I would recommend heading over to the PHP forum and starting a new thread. There are a lot of clever folks there who will be happy to help.