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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Location
    NL
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Filling out the fields in form

    Hi,

    First of all I'm completely new to CGI. Second is there anyone who
    can help do this:

    Let say this is the url:
    http://www.mydomain.com/cgi-bin/script.cgi?nr=123&fn=Bob&ln=Davids&em=b.davids@mydomain.com

    How can the nr, fn, ln and em be filled out in the html form in script.cgi, with the fields nr, fn, ln and em?

    Tx in advance,

    Gijs

  • #2
    New Coder
    Join Date
    Aug 2002
    Location
    san marcos TX
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts
    within your script, assuming you have parsed the input from the url..

    <input type=text name=em value=$fields{'em'}>

    then that value will show up in the form field, and they can change it if they want.

    hope this helps.

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Location
    NL
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks but...

    Hi Cedsn,

    Sorry, but as I said before, I'm really completly new to cgi, and
    surrounded with books and examples, I don't know how to
    parse the input from the url. If you could help me with that too?

    I've tried some examples, but....


    Tx

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    use cgi-lib for easiest results

    Part 1, Simple solution:

    1. Get a copy of the latest cgi-lib.pl
    2. Upload it to your cgi-bin and set permissions to 755.
    3. In your script, (somewhere near the very beginning - AFTER the first line declaring the location of perl), write this:

    require "cgi-lib.pl";

    Then, insert this somewhere in the beginning of your code:
    &ReadParse($in, $in_name, $in_type, $in_server_name);

    All of your variables will come out in the following format:

    $in{'nr'}
    $in{'ln'}

    Based on form input of say:

    <FORM METHOD="POST" ACTION="http://myserver.com/cgi-bin/myscript.pl">
    <INPUT TYPE="hidden" NAME="nr" VALUE="123">
    <INPUT TYPE="TEXT" NAME="ln" SIZE="14" value="Last Name" MAXLENGTH="30">
    <INPUT TYPE="submit" VALUE="Submit!">

    Next post, I'll show you how to do the subbing of this same input data, with some mods...
    Last edited by pager; 08-08-2002 at 11:37 PM.

  • #5
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Subbing the html form data; Part 2

    In the previous example, the html form... was a static page that used regular form expressions.

    To do a sub, the page needs to be generated dynamically... ie, read the html of the page into the script, and let it substitute the values - then, output the html page to the browser.
    Code:
    $base_path = "/home/user/htdocs/mytemplates/";
    $htmlformname = "mainform.html";
    #
    #Somewhere in your script, when it's time to output the form:
    &output_html;
    ...
    ..
    .
    sub output_html {
    $filetoopen = $base_path . $htmlformname;
    open (BROWSER, "<$filetoopen") || die "Cannot Open File";
    @outelement = <BROWSER>;
    close (BROWSER);
    for $inline (@outelement){
               s/zxvar1/$in{'nr'}/ig;
               s/zxvar2/$in{'ln'}/ig;
               s/zxvar3/$in{'fn'}/ig; # and so on...
               $outline .= $inline;}
    print $outline;
    }
    ####################################
    #In the html form template, the form coding will need to be changed to resemble something like this:
    #
    <FORM METHOD="POST" ACTION="http://myserver.com/cgi-bin/myscript.pl">
    <INPUT TYPE="HIDDEN" NAME="nr" VALUE="zxvar1">
    <INPUT TYPE="TEXT" NAME="ln" SIZE="14" VALUE="zxvar2" MAXLENGTH="30">
    <INPUT TYPE="TEXT" NAME="fn" SIZE="14" VALUE="zxvar3" MAXLENGTH="30">
    <INPUT TYPE="submit" VALUE="Submit!">
    #####################################

    Now, anytime this form template is displayed, it MUST be displayed by myscript or whatever your script's name is, or else if you simply call it by using an http://myserver.com/mytemplates/mainform.html,
    Then you'll end up with the input boxes displaying your sub vars, in otherwords, the text box will actually display "zxvar". When it's parsed through the script, the subbing will replace them with empty values the first time it's called because $in{'ln'} etc, will be null values.

    This code is quite loose, but if you're learning, it's easier to be loose in the beginning and then later on trim it up and eliminate some excess variables.

    If you have a LOT of variables to sub out, I've got a better routine but it swaps all of the variables on the html page to array variables.

    Note! You must use some obscure names for the sub'd variables, like "zxvar1".... do not use "number", or "last name", or anything like that because the script will replace all instances of these names found in your html page with the $in{'ln'} array values.

    Anything will work, just be sure they're extremely unique, using combinations that would never actually be input by someone using the form. In this I used numerics, but something like zxvarNR, zxvarLN, zxvarFN will work fine to make it easier to read.
    Just be sure that the sub lines match what's in your html page.

    Hope this helps.

  • #6
    New to the CF scene
    Join Date
    Aug 2002
    Location
    NL
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile THANKS

    Thanks a lot


  •  

    Posting Permissions

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