Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

WebForm: What I think should be easy enough...

Options
  • 13-10-2005 1:31pm
    #1
    Registered Users Posts: 3,357 ✭✭✭


    Hi all,
    I've looked at a ton of tutorials, but none of them offer any help as to how to proceed with this little problem I have.

    I would like to have a small webform, just one box and a submit button. The user either:
    1. Enters a number into a text box
    or
    2. Selects a number from a drop-down menu
    and then clicks on submit.

    The form then needs to return http://www.some.example.site.com/files/fileXX.jpg
    where XX is the number the user inputted or selected from the drop down.

    Is this possible?
    If so, could someone point me in the direction of a site that helps me out, or better yet, gives me an idea themselves.

    Thanks in advance
    -Ste


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    snappieT wrote:
    Hi all,
    I've looked at a ton of tutorials, but none of them offer any help as to how to proceed with this little problem I have.

    I would like to have a small webform, just one box and a submit button. The user either:
    1. Enters a number into a text box
    or
    2. Selects a number from a drop-down menu
    and then clicks on submit.

    The form then needs to return http://www.some.example.site.com/files/fileXX.jpg
    where XX is the number the user inputted or selected from the drop down.

    Is this possible?
    If so, could someone point me in the direction of a site that helps me out, or better yet, gives me an idea themselves.

    Thanks in advance
    -Ste

    It is definitely possible, but you need to tell us what system the webserver is running on. i.e. can you run ASP, PHP, JSP etc. Failing that, you can do it client side using JavaScript, but that is far from ideal as a good few people disable JavaScript, so it wouldn't work at all.

    Eoin


  • Registered Users Posts: 2,157 ✭✭✭Serbian


    If you have access to PHP on your web hosting, here is a really simple page that will do what you are looking for (although, I haven't actually tested it).

    [php]<?
    /* Define variables */
    $text = "No image selected";
    $error = "";

    /* See if the form has been POSTed */
    if ( $_SERVER == "POST" )
    {
    /* Check if the posted field is in fact an image */
    if ( !isset ( $_POST || !is_numeric ( $_POST ) )
    {
    $error = "<span style=\"color: #cc0000;\"><strong>Error:</strong> Please choose enter a valid number</span>";
    }
    else
    {
    /* Set the path to your images folder */
    $image = "path/to/image/file{$_POST}.jpg";

    /* Check if the file actually exists */
    if ( file_exists ( $image ) )
    {
    /* Show the image */
    $text = "<img src=\"$image\" alt=\"This is some image\">";
    }
    else
    {
    /* Show that the image doesn't exist */
    $text = htmlentities ( $image ) . " does not exist";
    }
    }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
    <html xmlns="http://www.w3.org/1999/xhtml"&gt;
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Cool Web Form Page!</title>
    <style type="text/css">
    <!--
    * {
    font: normal 10px Verdana;
    color: #333;
    }
    -->
    </style>
    </head>
    <body>
    <? if ( isset ( $error ) && !empty ( $error ) { print "<p>$error</p>"; } ?>
    <p><strong>Current Image:</strong></p>
    <p>
    <?=$text;?>
    </p>
    <form method="post" action="<?=$_SERVER;?>" name="getfile">
    <select name="image">
    <option>-- Please Select --</option>
    <option>22</option>
    <option>234</option>
    <option>21</option>
    </select>
    <input name="submit" type="submit" value="Submit" />
    </form>
    </body>
    </html>
    [/php]


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Serbian's should work fine. However, I don't think it's reasonably possible to do what you're looking for - I assume you're looking for a ComboBox (where you can type in your choice or choose from a menu).

    If you google it, you'll find a few implementations using Javascript and/or .NET, but to ensure compatibility across the board I'd say you're better off running with two fields - a text box and a drop-down, including a radio button so the user can indicate which they want to use.

    In theory, you could do without the radio, and just use the one which hasn't returned a default value, but what happens if they put something in the textbox and also choose a value from the dropdown?

    seamus (who thinks too much about these kinds of things)


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    If you need this done now and don't have time to mess around, go to http://www.scriptlance.com and pay some Russian $5 to do it for you.


  • Registered Users Posts: 3,357 ✭✭✭snappieT


    Ooh, thanks for the quick replies!

    The server supports php and perl.
    I really don't want a russian to do it, I'd kinda like to learn...
    And it doesn't need to be both dropdown and text box. Whichever is easier to implement.

    Also bear in mind that the images aren't called 01.jpg, 02.jpg: they are CommonText01.jpg, CommonText02.jpg. This can't be changed, as the files are configed to work with an existing application on the server, and I'm not touching that config file again!

    Ultimately, it'd be great if I could make something like

    <DROPDOWN MENU>
    <TEXT BOX>


    The dropdown menu selects the photo album: Album1, Album2, Album3 etc. (there are currently only 4)

    The textbox selects the photo number.

    The path to images are http://example.com/subsite/AlbumName/images/AlbumNameImageNumber


  • Advertisement
  • Registered Users Posts: 2,157 ✭✭✭Serbian


    I think two drop downs would make more sense. The user would select the album from the first drop down and the second drop down would automatically populate with the list of photos from the album.

    This is quite simple to do, and I can certainly give you a start on it, but have you tried coding anything yourself yet?

    EDIT: Also, does every folder in the subsite directory (http://example.com/subsite/) link to an album, or are some folders links to other things?


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    PHP, although it is HORRIBLE, is an extremely easy language to learn, and it's handy. Go look. It shouldn't take long to get the hang of it.


  • Registered Users Posts: 3,357 ✭✭✭snappieT


    So there's no CGI that I have to mess around with?

    @Serbian: Each subfolder is some html and flash that currently displays the photos, and the photos themselves.


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    Er, strictly speaking, PHP is sort of a form of CGI (though implementation generally differs). But it's easy. And it's very well-supported.


  • Registered Users Posts: 5,335 ✭✭✭Cake Fiend


    rsynnott wrote:
    although it is HORRIBLE

    Eh? How so? Coming from a C background, to me PHP is a godsend!

    /me wanders off cursing about pointers, memory allocation, typecasting...


  • Advertisement
  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    The undeclared variables, the lack of strong typing.... positively encorages bad programming.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    rsynnott wrote:
    The undeclared variables, the lack of strong typing.... positively encorages bad programming.

    I'd agree. Ideally one would learn PHP after getting to grips with a strongly-typed language like Java or C. PHP is an absolute dream to code with though.


Advertisement