Results 1 to 6 of 6

Thread: Editing this script...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Editing this script...

    Download the attachment, does anyone know how I would beable to make a form on a webpage so people can enter their name and it'll goto a new page showing the image with the name they entered? The only way you can do it right now is by entering the name after ?=
    Attached Files Attached Files

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Editing this script...

    I can't download the attachment right now, but have a read of HTML Forms and Input.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Editing this script...

    This is what I've done so far:-

    Code:
    <form name="input" action="localhost/sig/stats.php/stats/$name" method="get">
    
    Name: 
    <input type="text" name="name" value="" size="20">
    
    <input type="submit" value="Submit">
    
    
    </form>
    But when I click submit it doesn't get the name so the signature has no name on it, is there anything wrong in that code?

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Editing this script...

    yes. that's wrong.

    I haven't downloaded the attachment (and I can't right now -- so really if you could post anything relevant that would be great!), but.. do you just basically want to build the image using the form rather than editing the URL manually?

    first off, don't forget the HTTP part of your URL.

    secondly, you should understand how GET works. if you submit a form via GET, then ALL elements in the form that are NAMED objects will be reproduced in the query string. this means that if you were submitting to image.php, and you have a form with an input named "name", then the form would essentially submit to.. image.php?name=[value_you_put_in_the_field]. understand? so.. with what you were currently doing in the example you posted, you would essentially be creating: "localhost/sig/stats.php/stats/$name?name=[value]" (and since you didn't echo out '$name', it would literally show the scalar character). so, if your script works by going to 'http://localhost/sig/stats.php?name=[value]' (to display [value] in the image), then you can easily make a form that just submits to that URL.
    PHP Code:
    <form name="input" action="http://localhost/sig/stats.php" method="get">
      <
    input type="text" name="name" size="20 />
      <input type="
    submit" value="go" />
    </form> 
    then, you'll be submitting to 'http://localhost/sig/stats.php?name=[value]'. however, because of the way you formatted your URL (/sig/stats.php/stats/[value], rather than using a query string), you might need to get a little involved. in this case, you could POST your form and then just redirect with a header to the correct URL. something like this:
    PHP Code:
    <?php
      
    //submitting?
      
    if($_SERVER['REQUEST_METHOD'] == "POST"){
        
    //make sure our variable is not empty and does exist
        
    if(isset($_POST['name']) && $_POST['name'] != ""){
          
    //redirect
          
    header("Location: http://localhost/sig/stats.php/stats/" urlencode($_POST['name']));
          exit;
        }else{
          
    //something was empty, show the form again
          
    $error true;
        }
      }

      if(isset(
    $error) || $_SERVER['REQUEST_METHOD'] != "POST"){
        
    //show the form
    ?>
    <form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <input type="text" name="name" size="20" />
      <input type="submit" value="go" />
    </form>
    <?php ?>
    so.. basically, when you submit that script it will submit to itself but redirect the user to the URL formatted like: http://localhost/sig/stats.php/stats/[value]

    hope that made sense! I'm in sort of a rush. all untested code, but it should be fine. post any questions you might have!

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 2007
    Posts
    190

    Re: Editing this script...

    Thanks, I got it to work but one last thing, is it possible to make it not redirect show when the button is pressed the image shows up and a textbox that'll give the URL to it? And heres the code (had to edit yours abit)


    Code:
    <?php
      //submitting?
      if($_SERVER['REQUEST_METHOD'] == "POST"){
        //make sure our variable is not empty and does exist
        if(isset($_POST['name']) && $_POST['name'] != ""){
          //redirect
          header("Location: http://localhost:2000/sig/stats.php/stats/". urlencode($_POST['name']. ".gif"));
          exit;
        }else{
          //something was empty, show the form again
          $error = true;
        }
      }
    
      if(isset($error) || $_SERVER['REQUEST_METHOD'] != "POST"){
        //show the form
    ?>
    <form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <input type="text" name="name" size="20" />
      <input type="submit" value="go" />
    </form>
    <?php } ?>
    Heres a example:-

    http://www.draynor.net/forum/stat-signatures.html

  6. #6
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Editing this script...

    that's easy.

    PHP Code:
    <?php
      
    //submitting?
      
    if($_SERVER['REQUEST_METHOD'] == "POST"){
        
    //make sure our variable is not empty and does exist
        
    if(isset($_POST['name']) && $_POST['name'] != ""){
          
    //display image
          
    $img "http://localhost:2000/sig/stats.php/stats/{$_POST['name']}.gif";
    ?>
    <img src="<?php echo $img?>" /><br /><br />
    <input type="text" value="<?php echo htmlentities($img); ?>" size="20" />
    <?php
        
    }else{
          
    //something was empty, show the form again
          
    $error true;
        }
      }

      if(isset(
    $error) || $_SERVER['REQUEST_METHOD'] != "POST"){
        
    //show the form
    ?>
    <form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
      <input type="text" name="name" size="20" />
      <input type="submit" value="go" />
    </form>
    <?php ?>

Posting Permissions

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



Click Here to Expand Forum to Full Width