Results 1 to 7 of 7

Thread: CGI Input

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225

    CGI Input

    Hi,

    I'm having an issue with a CGI program I'm trying to write. I have a lot of experience in Visual Basic so I'll try to explain what I want to do in those terms...

    Let's say I have a txt file filled with a bunch of records. Each record takes up 4 lines. The first three records are strings, the final one is an integer (This doesn't matter in CGI though, does it, correct...?).

    Is it possible to load these records into a multidimensional array in CGI? i.e. in Records[A,B], A would be the record's ID and B would be one of the 4 inputted lines.

    Can anyone shed any light on if this is possible, and if it's not, what the alternatives are?

    How would I input/seperate these records? Can anyone supply any code, please?

    BTW, also, is it possible to have 'forms within forms'? What I mean is, say if I have the following...

    ---

    -Record here-
    Record's textarea here
    Record's Delete Button | Record's Options Button

    -Record here-
    Record's textarea here
    Record's Delete Button | Record's Options Button

    -Record here-
    Record's textarea here
    Record's Delete Button | Record's Options Button

    ALL Record's Save Changes Button

    ---

    Meaning, you have the save changes button which saves all the textareas, but you also have individual delete/options buttons for EACH record... So it'd look something like:

    Code:
    <form>
        <form>
            'Input, Buttons, etc.
        </form>
        <form>
            'Input, Buttons, etc.
        </form>
        <form>
            'Input, Buttons, etc.
        </form>
        'Input, Buttons, etc.
    </form>
    Would that work, with each input field/button being restricted to it's 'parent' field...?

    Thanks,

    -Git
    Last edited by git; Feb 18th, 2003 at 05:20 AM.

  2. #2
    Member
    Join Date
    Jan 2003
    Posts
    44

    Re: CGI Input

    git
    The first three records are strings, the final one is an integer (This doesn't matter in CGI though, does it, correct...?).
    This doesn't matter in Perl. CGI is a network protocol.

    Is it possible to load these records into a multidimensional array in CGI? i.e. in Records[A,B], A would be the record's ID and B would be one of the 4 inputted lines.
    In Perl, yes.

    How would I input/seperate these records?

    Code:
    use Fcntl qw{:flock};
    
    my @rec;
    open TXT, 'txtfile.txt' or die $!;
    flock TXT, LOCK_SH;
    
    until (eof TXT) {
        chomp(my $id = <TXT>);
        for (1 .. 3) {
            chomp(local $_ = <TXT>);
            $rec[$id]{$_} = 1;
        }
    }
    
    close TXT or die $!;
    BTW, also, is it possible to have 'forms within forms'?
    No. Forms are not allowed to contain other forms. What you could do is have a delete column with checkboxs. When the form is submitted any records whose delete checkbox is true, remove them.
    Last edited by jeffmott; Feb 18th, 2003 at 12:13 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Awesome, thank you for your help!

    Another question about forms then... If forms-within-forms isn't possible, is it possible to have multiple SUBMIT buttons within a single form? If it is, what CGI code would I use to tell which one was clicked?

    If I do that, can I have something like this - a bunch of records with hidden values for EACH button... i.e.:

    Code:
    <form>
    -record-
    <input type=hidden etc. name=miscvalue value=1>
    <button>
    
    -record-
    <input type=hidden etc. name=miscvalue value=2>
    <button>
    
    -record-
    <input type=hidden etc. name=miscvalue value=3>
    <button>
    </form>
    If I submit the form, depending on the button, would the 'miscvalue' value be different, aka if I clicked the 3rd submit button would it be 3, or would the second be 2, etc.?

    Thanks,

    -Git

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    BTW, I can't figure out how to print data from the array to a HTML page (using the array code you supplied). I tired all sorts of things including putting "print "$rec[$id]{$_}";" under the "$rec[$id]{$_} = 1;" line, but it doesn't work... All I need is an 'foreach' routine that goes through each of the records. How do I do this? (I've never used multidimensional arrays in CGI before)

    -Git

  5. #5
    Member
    Join Date
    Jan 2003
    Posts
    44
    git
    is it possible to have multiple SUBMIT buttons within a single form
    Yes, if the name and value attributes have been set then those values associated with the button clicked will be passed. The only downside to this is that the value is also used for the button's label.

    If I do that, can I have something like this - a bunch of records with hidden values for EACH button
    You can have a bunch of hidden fields, but they will all be submitted with the form regardless of which submit button was used to initiate the submission.

    I can't figure out how to print data from the array to a HTML page (using the array code you supplied)
    What do you want it to print out? It should only print "1". You had said you wanted to be able to index the records such that...
    Records[A,B], A would be the record's ID and B would be one of the 4 inputted lines
    ...and it is indexed as such, but you never specified what value they each should be set to. So in the code above I simply set them to a true value, 1. You probably should be a little more specific about how you want the data structured as well as how the input data is formatted. Alot of what I gave was based on a little guess work.

    All I need is an 'foreach' routine that goes through each of the records. How do I do this? (I've never used multidimensional arrays in CGI before)
    I've never used multidimensional arrays in CGI either, since CGI is a network protocol.
    Code:
    for (keys %{$rec[$some_id_num]}) {
        ...
    }

  6. #6
    Addicted Member Phenix's Avatar
    Join Date
    Sep 2002
    Location
    Near A Cube
    Posts
    228

    Red face Don't I feel like a dolt?

    This would answer my question at http://vbforums.com/showthread.php?s=&threadid=231353 , but how do you execute it? Please give an example.

    Yes, if the name and value attributes have been set then those values associated with the button clicked will be passed. The only downside to this is that the value is also used for the button's label.
    I can live with this. But I cannot seem to access the value. Can they all be named the same?
    edit=val1
    edit=val2
    edit=val3

    Test for $edit == ?

    or different names

    edit1=val1
    edit2=val1
    edit3=val1

    Test for $editN == not null ??? (but won't they all have values?)

    I'm not accessing $edit under PHP (but I'm a newb). I think foreach will give me a value since they all have the value of their row once it is in the html form, {like you "for (keys ..." statement}.

  7. #7
    Member
    Join Date
    Jan 2003
    Posts
    44
    Phenix
    This would answer my question at http://vbforums.com/showthread.php?s=&threadid=231353 , but how do you execute it? Please give an example.
    I can't give an example of that very well since it is in a different language than the one this thread has used thus far.

    Can they all be named the same?
    Yes. If only one control of a given name is submitted this is no trouble at all. If more than one control is submitted of a given name then it depends on the quality of your parameter parser whether you'll be able to retrieve all the values.

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