in reply to CGI - Parsing many options.

I don't actually quite understand what your question is.

What do you want to do with this information?

If it's been passed by CGI.pm, it's already in a hash for you, or it can be.

Are you saying that $op1 contains two scalars separated by a hyphen and you don't know how to split it?

Please give more detail -- some examples of the values and what you want to do with them.

Oh, and if you've got more than forty fields in a form, it might be time to think multi-page...



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: Re: CGI - Parsing many options.
by jdtoronto (Prior) on Aug 01, 2003 at 14:39 UTC
    Cody:

    Seems that I should not ask questions after midnight!

    Some points:

  • I can split the two scalars, thats isn't a problem :)
  • The options need not appear on the form, they can be hidden fields.
  • I would ideally like to be able to refer to them like this: $value = $options{option#}{scalar1 or scalar2}

    Here is what is happening, we have been using a hosted shopping cart for some years, we can no longer use it because they do not support our new payment processor. Because we have a huge base of statically coded HTML pages, going back to 1996, built on this cart I need to emulate its operation. In a simple example this is what I get from the form:

    item : p-1723^I-0100^Internet book^op1op3op5^1^^^^^^ op1 : Single copy - $69.95 op3 : Hard cover - $10.00 op5 : Signed - $10.00
    Now, the right hand portion of the option, if present, in the case of options1, 3 & 5 will be added to produce the final price. In this example the total price is op1+op2+op3 or $89.95.

    The left portion, the text part, will be appended to the description. However, here comes my twist, according the documentation for the original script, op2 and op4 if returned from the form needs to be interpolated inthe description, it could be like this:

    op2 : <br>Cover: op4 : <br>
    So that when the description is displayed it will look like:
    Single copy Cover: Hard cover Signed
    In a single cell in a table.

    My question is this. How would you, or the other monks, suggest I create the hash I would like to use. Or even better, should I be using a hash like that at all?

    Your respectful Perl novice,

    John

      Do also remember that the CGI script should validate what it gets from the form. Remember that the user can save the form on his/her machine, alter the numbers in the saved page, and then submit the altered form. "Gee, I don't think signed is worth $10.00. I'll make it $0.00."

      Never trust the browser.

      You're probably already doing this, but a reminder never hurts.