Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Creating a simple form that displays field output on same page?

    Can someone help me with this? I posted in wrong forum to being with, so i'll link to that.

    http://www.codingforums.com/asp/120854-creating-simple-form-displays-field-output-same-page.html#post597623

    any help appreciated

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    You're missing the closing bracket, ), from the if.

    PHP Code:
    <?php
    if (isset($_REQUEST["FirstName"])) { 
       
    $reply $_REQUEST["FirstName"]; 
    }
    if (isset(
    $_REQUEST["LastName"])) { 
       
    $reply += $_REQUEST["LastName"]; 
    }
     
    echo 
    "Thanks for applying, ".reply;
    ?>
    Also I would use $_GET or $_POST, depending on the method your form uses, instead of $_REQUEST.

  • #3
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    Also to post to the same page you use $PHP_SELF, as in the sample below:

    PHP Code:
    <form method="post" action="<?php echo $PHP_SELF;?>">
    Leonard Whistler

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    alright that php self didn't work, thanks for suggestion though. I'm gonna try and make it print on another page now. Let me show u exactly what i have to make it easier:

    THE PAGE WHERE TO REGISTER:

    tournament.php

    Code:
    <?php 
    
    // standard hack prevent 
    define('IN_PHPBB', true); 
    $phpbb_root_path = './'; 
    include($phpbb_root_path . 'extension.inc'); 
    include($phpbb_root_path . 'common.'.$phpEx); 
    
    // standard session management 
    $userdata = session_pagestart($user_ip, PAGE_TOURNAMENT); 
    init_userprefs($userdata); 
    
    // set page title 
    $page_title = 'TOURNAMENT'; 
    
    // standard page header 
    include($phpbb_root_path . 'includes/page_header.'.$phpEx); 
    
    
    
    
    if (isset($_POST["FirstName"])) { 
       $reply = $_POST["FirstName"]; 
    }
    
    echo "Thanks for applying, ".reply;
    
    
    
    // assign template 
    $template->set_filenames(array( 
            'body' => 'tournament.tpl') 
    ); 
    
    $template->pparse('body'); 
    
    
    ?>


    Template for Tournament.php:

    Code:
    <HTML>
    
    <table width="100%" cellspacing="0" cellpadding="2" border="0" align="center">
     
    
     
     
     <tr> 
    	<td align="left" valign="bottom"><span class="gensmall">
    	<!-- BEGIN switch_user_logged_in -->
    	{LAST_VISIT_DATE}<br />
    	<!-- END switch_user_logged_in -->
    	{CURRENT_TIME}<br /></span><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a></span></td>
    	<td align="right" valign="bottom" class="gensmall">
    		<!-- BEGIN switch_user_logged_in -->
    		<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
    		<!-- END switch_user_logged_in -->
    		<a style="cursor:hand" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://snkclan.nuclearfallout.net');" class="gensmall">Make SNK Your Homepage</a></span></td>
    
      </tr>
    </table>
    
    
    
    
    <table width="100%" cellpadding="1" cellspacing="1" border="0">
      <tr>
        <td style="vertical-align:top;">
        
        
          <table width="100%" cellpadding="5" cellspacing="5" class="forumline">
           <tr>
    	     <th width="center" cellspacing="2" cellpadding="2" class="thCornerL" height="25" nowrap="nowrap">&nbsp;Tournament Registration&nbsp;</th>  
           </tr>
          
          
          
          <tr>
             <td align="center" class="row1"><span class="nav">
    
    
    
    
    
    
    <form method="post" action="registered.php"  <!-- action may also be myform.php, depending on your Server Side language -->
    Counter-Strike Name: <input type="text" name="FirstName" size="10" /><br />
    <input type="submit" value="Submit" name="B1" />
    </form>
    <HTML>
    Page to be taken and have names printed after registering:

    registered.php

    Code:
    <?php 
    
    // standard hack prevent 
    define('IN_PHPBB', true); 
    $phpbb_root_path = './'; 
    include($phpbb_root_path . 'extension.inc'); 
    include($phpbb_root_path . 'common.'.$phpEx); 
    
    
    // standard session management 
    $userdata = session_pagestart($user_ip, PAGE_REGISTERED); 
    init_userprefs($userdata); 
    
    // set page title 
    $page_title = 'REGISTERED'; 
    
    // standard page header 
    include($phpbb_root_path . 'includes/page_header.'.$phpEx); 
    
    // assign template 
    $template->set_filenames(array( 
            'body' => 'registered.tpl') 
    ); 
    
    $template->pparse('body'); 
    
    
    ?>

    Template for registered.php

    Code:
    <HTML>
    
    <table width="100%" cellspacing="0" cellpadding="2" border="0" align="center">
     
    
     
     
     <tr> 
    	<td align="left" valign="bottom"><span class="gensmall">
    	<!-- BEGIN switch_user_logged_in -->
    	{LAST_VISIT_DATE}<br />
    	<!-- END switch_user_logged_in -->
    	{CURRENT_TIME}<br /></span><span class="nav"><a href="{U_INDEX}" class="nav">{L_INDEX}</a></span></td>
    	<td align="right" valign="bottom" class="gensmall">
    		<!-- BEGIN switch_user_logged_in -->
    		<a href="{U_SEARCH_NEW}" class="gensmall">{L_SEARCH_NEW}</a><br /><a href="{U_SEARCH_SELF}" class="gensmall">{L_SEARCH_SELF}</a><br />
    		<!-- END switch_user_logged_in -->
    		<a style="cursor:hand" onClick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://snkclan.nuclearfallout.net');" class="gensmall">Make SNK Your Homepage</a></span></td>
    
      </tr>
    </table>
    
    
    
    
    <table width="100%" cellpadding="1" cellspacing="1" border="0">
      <tr>
        <td style="vertical-align:top;">
        
        
          <table width="100%" cellpadding="5" cellspacing="5" class="forumline">
           <tr>
    	     <th width="center" cellspacing="2" cellpadding="2" class="thCornerL" height="25" nowrap="nowrap">&nbsp;Registered Users&nbsp;</th>  
           </tr>
          
          
          
          <tr>
             <td align="center" class="row1"><span class="nav">
    	 
    	 
    	 
    	 
    <HTML>
    I hope this helps. As of now, when a name is entered and submitted, it takes me to registered.php. But it does not post or print anything.

  • #5
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    OK, you need to move this code:
    PHP Code:
    if (isset($_POST["FirstName"])) { 
       
    $reply $_POST["FirstName"]; 
    }
     
    echo 
    "Thanks for applying, ".reply
    out of tournament.php and into registered.php since that is where your form is pointed to. Oh and your form tag in the Template for Tournament.php looks like it's missing a >.

    Also since you're using phpbb you'll have to check their documentation on how to assign variables so you can display them in templates. I'm not sure whether echo "Thanks for applying, ".reply; will have the desired effect.

    P.S. I think Len meant $_SERVER['PHP_SELF'].
    Last edited by mcjwb; 08-08-2007 at 11:32 PM. Reason: spelling and extra content.

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it doesnt look like the echo does, i saw it printing thanks for applying at the top of the page before even applying.

    I should also mention my forums use sql for storing so im assuming im gonna have to alter or insert a table somewhere.....man i didnt think it would be this complicated, damnit. IT SEEMS SO SIMPLE.

    snkclan.nuclearfallout.net is my site if that helps it all, ill keep messing with the code

    EDIT: Tried switching it around, no dice.

    Will take me to registered.php. It seems to me that there is nothing telling it to print or post on that page, and to actually post in there i think i require a mysql table.

    I'd rather it just print the person's name on registered.php along with everyone else who does this, nothing fancy, just to get it to print their entry in the form
    Last edited by hatz; 08-08-2007 at 11:41 PM.

  • #7
    New Coder
    Join Date
    Aug 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    fyi this kid above is spamming, that website is bs.

    Still workin on the problem if anyone can help, thanks. Perhaps ill try in the sql section as well cuz i think i need that too.

  • #8
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    This is a simple form that displays field output on same page. It should give you an idea of what to do.

    index.php
    PHP Code:
    <html>
    <body>
    <?php
    $first_name 
    $_POST["first_name"];
    $last_name $_POST["last_name"];

    echo 
    "Thanks for applying $first_name $last_name";
    ?>
    <br />
    </table><br />
    <form method="post" action="<?php echo $PHP_SELF;?>">
    First Name: <input type="text" size="30" maxlength="30" name="first_name" /><br /><br />
    Last Name: <input type="text" size="30" maxlength="30" name="last_name" /><br /><br />
    <input type="submit" value="submit" name="submit" /><input type="reset" value="clear" />
    </form>
    </body>
    </html>
    Leonard Whistler

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Quote Originally Posted by hatz View Post
    I'd rather it just print the person's name on registered.php along with everyone else who does this, nothing fancy, just to get it to print their entry in the form
    It sounds like you want it to print a list of names from everyone who has submitted your form, is this correct?
    To do this you need to store the submitted name somewhere on your server, whether that be a database, an xml file or a text file, otherwise when you leave the page the submitted name will be lost. Your actual html file never gets modified.

    So as well as storing the submitted names, you will also need a method of retrieving the names and displaying them.

    It is not a trivial matter, but once you are familiar with php,mysql and html it becomes second nature .

    You also have the complication of learning and using the phpbb template system, which changes how you would normally do things in php.

    To get back to your problem, if we ignore the fact you are using phpbb for now, just to demonstrate how forms and php work. Modify your registered.php file to simlpy read:
    PHP Code:
    <?php
    if (isset($_POST["FirstName"])) { 
       
    $reply $_POST["FirstName"];
       echo 
    "Thanks for applying, ".reply;
    }
    else{
       echo 
    "Form not submitted.";
    }
    ?>
    Now if you go ahead and submit your form you should see "Thanks for applying, TheNameYouEntered" without the quotes and TheNameYouEntered replaced with the value you put in the text field.
    Now if you go to the address bar in your browser it should say .../registered.php, click on it and press enter.
    Now the page should change to say "Form not submitted.";

    Hopefully this should help you understand the relationship between html forms and php.

    Now all you have to do is save the submitted name to a database or something and write the code to retrieve it!

  • #10
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post

    Thumbs up

    Quote Originally Posted by Len Whistler View Post
    This is a simple form that displays field output on same page. It should give you an idea of what to do.

    index.php
    PHP Code:
    <html>
    <body>
    <?php
    $first_name 
    $_POST["first_name"];
    $last_name $_POST["last_name"];

    echo 
    "Thanks for applying $first_name $last_name";
    ?>
    <br />
    </table><br />
    <form method="post" action="<?php echo $PHP_SELF;?>">
    First Name: <input type="text" size="30" maxlength="30" name="first_name" /><br /><br />
    Last Name: <input type="text" size="30" maxlength="30" name="last_name" /><br /><br />
    <input type="submit" value="submit" name="submit" /><input type="reset" value="clear" />
    </form>
    </body>
    </html>
    Just following on from Whistler, nice example btw, you just better make sure that the $_POST variables are set and not empty, else errors will appear on your page, like variable not set and it would echo the thankyou message before you have submited anything. Also if $PHP_SELF isn't working for you, you can easily just put the name of the current script in the action area or leave it blank both methods will post it to itself.

    PHP Code:
    <html>
    <body>
    <?php
    if(isset($_POST["first_name"]) && $_POST["last_name"]))
    {
      if(empty(
    $_POST["first_name"]) || empty($_POST["last_name"]))
      {
        die(
    "Invalid submission!");
      }
      
    $first_name $_POST["first_name"];
      
    $last_name $_POST["last_name"];
      echo 
    "Thanks for applying $first_name $last_name";
    }
    ?>
    <br />
    </table><br />
    <form method="post" action="">
    First Name: <input type="text" size="30" maxlength="30" name="first_name" /><br /><br />
    Last Name: <input type="text" size="30" maxlength="30" name="last_name" /><br /><br />
    <input type="submit" value="submit" name="submit" /><input type="reset" value="clear" />
    </form>
    </body>
    </html>

  • #11
    New Coder
    Join Date
    Aug 2007
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright, thanks. It seems to be working better now. But, it is still not displaying the name on the page after submitted. And also, how would i use a txt file to save the names and display it?


  •  

    Posting Permissions

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