SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Addict
    Join Date
    Aug 2013
    Location
    New Zealand
    Posts
    302
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    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

  3. #3
    SitePoint Addict
    Join Date
    Aug 2013
    Location
    New Zealand
    Posts
    302
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    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.

    index.html
    Code:
    <form action="index.php" method="post">
      <label for="name">Enter your name:</label>
      <input Type="text" name="name" id="name "/><br>
      <input type="submit" />
    </form>
    Then in index.php you can access whatever data has been sent.

    index.php
    Code PHP:
    <?php 
      $name = $_POST['name'];
      echo "Hello, " . $name;
    ?>

    Is this the kind of thing you are after?

  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

    Example:

    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.

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, think I found my solution here: http://www.w3schools.com/php/php_forms.asp

  7. #7
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Xilica View Post
    Actually, think I found my solution here: http://www.w3schools.com/php/php_forms.asp
    Erm, did you actually read my answer above?
    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/

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Erm, did you actually read my answer above?
    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?

  9. #9
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,996
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Quote Originally Posted by Xilica View Post
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •