Get array as post variable from textarea

Discussion in 'HTML & Website Design' started by unitedlocalbands, Aug 2, 2008.

  1. #1
    How can I use a textarea to create an array in a post variable?

    I want to be able to enter multible emails into a textarea and then submit the values to the action page as an array to be run in a SQL statment.

    Any is much appreciated.
     
    unitedlocalbands, Aug 2, 2008 IP
  2. blueroomhosting

    blueroomhosting Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    It's not something that can be done directly with the textarea. You need a server-side technology to break down the submitted string in the POST field. Most programming languages have a function that splits up a string. For example, to split by line in PHP:

    $values = explode("\n", $_POST['email_addresses']);
    Code (markup):
    substitute whatever delimiting character you want into the first argument. Or you can use split() or preg_split() to split on regex if you want to support multiple delimiters.
     
    blueroomhosting, Aug 2, 2008 IP
  3. unitedlocalbands

    unitedlocalbands Well-Known Member

    Messages:
    246
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Thank you for the response. I use coldfusion for my server script so i will do some more searching on how to create an array,

    I know that I can create an array by using
    
    
    <cfset my_array_name = ArrayNew[1]>
    
    
    Code (markup):
    Then I think I can maybe do:
    
    
    <cfset my_array_name = #form.textarea_name#>
    
    
    Code (markup):
    not sure if this is going to break apart the data in the textarea though...

    I have to do some more searching though,

    thanks again.
     
    unitedlocalbands, Aug 2, 2008 IP