Accepting input and then displaying it on a second page

Discussion in 'PHP' started by Law-Dude, Nov 1, 2009.

  1. #1
    Hi,

    I don't know much about PHP, but as I understand it, it's good for web applications.

    I want to make a site where one of the pages asks for input on a form from users for certain questions, then fills in certain text on a second page using that input and gives the user the option to send the new page to their printer.

    For example, the user gives inputs A, B, on the first page, and the second page would be something like:

    "The person picked up the A and handed it to B."

    Does anybody know of an online tutorial for this? I have looked up PHP form guides but they all talk about accepting input for reasons other than display.

    Alternatively, is their software available to automatically generate this kind of form?

    Additionally, is it possible to put Adsense on a PHP page but not have it show up when the user decides to send it to their printer?

    Any responses are greatly appreciated.
     
    Law-Dude, Nov 1, 2009 IP
  2. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check out this thread for a list of free PHP ebooks for download. If you're a beginner, a few of the titles should be really helpful.

    What kind of input do you want to have? radio buttons? text fields?

    Here's a basic demo with text fields.

    Here's the html
    
    <form action="form.php" method="POST">
    Full Name: <input type="text" name="fullName"><br />
    <input type="submit">
    </form>
    
    Code (markup):
    And here's the code for form.php, which the PHP file that the data from the form is being sent to.

    
    <?
    echo "Hello, $_POST[fullName]";
    ?>
    
    Code (markup):
    It's pretty easy once you get the hang of it.

    I haven't seen anything. But, if you learn a bit more PHP past this stage, you can create a small program that would generate this type of form for you.

    That's more of a CSS trick then a PHP trick.

    
    @media print {
        #adsense {
         display: none;
        }
      }
    
    Code (markup):
    will completely remove the CSS div id "adsense" when printing the page.

    You can also have a "print page" button, which would use a PHP script instead of the CSS, to create a printable page. I think the CSS ie the easiest if your layout isn't too complicated.
     
    organicCyborg, Nov 1, 2009 IP
    Law-Dude likes this.
  3. Darkhodge

    Darkhodge Well-Known Member

    Messages:
    2,111
    Likes Received:
    76
    Best Answers:
    1
    Trophy Points:
    185
    #3
    Hey,


    PHP is very useful so it's good you're interested in it! :D

    Anyway what you require is very simple. First lets make a form with 2 text fields. I'm going to call the form page "page1.html" and the output page "page2.php", very creative naming huh? :)

    page1.html
    
    <html>
    <head>
    <title>Example Form</title>
    </head>
    <body>
    <form name = "quiz" action = "page2.php" method = "post>
    <input type = "text" name = "name">
    <input type = "text" name = "age">
    <input type = "submit">
    </form>
    </body>
    </html>
    
    HTML:
    The form will now send the information within the form via the POST method to page2.php. We now just need to get page2.php to accept those values and print it out accordingly:

    page2.php
    
    <?PHP
    
    // Get the variables that were sent via POST
    $name = $_POST['name'];
    $age   = $_POST['age'];
    
    // Print out the information
    print <<<HERE
    
    <html>
    <head>
    <title>Result</title>
    </head>
    <body>
    <h1>Hi $name</h1>
    
    <p>From the form you submitted we can see that your name is <b>$name</b> and you are <b>$age</b> years old!</p>
    </body>
    </html>
    HERE;
    
    ?>
    
    Code (markup):
    Don't forget in PHP variable names are case sensitive. Also the "print <<<HERE" and "HERE;" tags basically says "print anything from <<<HERE to HERE". One thing to note about coding this way is that the "<<<HERE" shouldn't have any spaces after it (on the same line). Also "HERE;" needs to be at the beginning of the line and also shouldn't have any spaces after it.

    That is a very simple example without any verification.

    In terms of reference material, the following are great resources:


    Anyway hope that helped :)


    Regards,

    Hodge
     
    Darkhodge, Nov 1, 2009 IP
    Law-Dude likes this.
  4. youngone324

    youngone324 Peon

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    and if your getting something from the url use this


    $object = $_GET['object'];
    print' $object';
     
    youngone324, Nov 1, 2009 IP
    Law-Dude likes this.
  5. Law-Dude

    Law-Dude Active Member

    Messages:
    285
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #5
    Thanks everybody. Your posts were very helpful. :)
     
    Law-Dude, Nov 1, 2009 IP