SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Variable Email recipients

    I have a form that is processed via submit to the server script "mailback.pl". I need the ability to have the form user choose from a drop-down input of potential recipients, of the form, to select one or more people to receive the data from the form. What kind of function would I need write to make this possible?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Firstly, you'd need to add to the HTML form, providing something like a select list of options, or perhaps select boxes. Then the processing script needs to be added to so that it collects and sends that extra data.

    Did you write the script yourself? .pl is Perl, isn't it? That means this is in the wrong forum.

  3. #3
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am sorry, I didn't mean to suggest that I needed a server side script written to process this form (I am using the pearl script "mailback.pl"), but that I needed a piece of JavaScript that would change the form input value of "mailitto" from what the user would select from a dropdown form input.

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,592
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Do you really need JS for that? Why not just use a standard select list? Then you don't have to worry about users having JS off, too.

  5. #5
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You'll have to excuse my ignorance, but I don't know of a way that I can get multiple selections from a dropdown input to alter where the form data goes to.

  6. #6
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After some more research, it seems that I should attempt this with multiple checkbox inputs, but unlike the input>select, there is no one global name="" for the input. The name value would have to be assigned on each checkbox, would it not? If that is so, then I can't set the form input to multiple checkboxes. I am I correct?

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by svoltmer View Post
    After some more research, it seems that I should attempt this with multiple checkbox inputs, but unlike the input>select, there is no one global name="" for the input. The name value would have to be assigned on each checkbox, would it not? If that is so, then I can't set the form input to multiple checkboxes. I am I correct?
    There are a couple of standard options.

    When using multiple checkboxes, you can use square brackets at the end of the name, which results in the checked ones being able to be accessed as an array.

    HTML Code:
    <ul>
        <li><input type="checkbox" name="sendto[]" value="tom"> Tom</li>
        <li><input type="checkbox" name="sendto[]" value="dick"> Dick</li>
        <li><input type="checkbox" name="sendto[]" value="harry"> Harry</li>
    </ul>
    Alternatively you can use a multiple select, where Ctrl-clicks are used to select additional people from the list.

    HTML Code:
    <select name="sendto[]" multiple="multiple">
        <option value="tom">Tom</option>
        <option value="dick">Dick</option>
        <option value="harry">Harry</option>
    </select>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your input, but after changing the "name=" to include the brackets I receive the error "Recipient names must be specified". I am using the "mailback.pl" script to process it. So my input statement looks like this:

    <form id="formID" method="POST" action="http://www.somedomain/cgi-bin/mailback.pl" name="some-form-name">
    <input name="mailitto" value="" type="hidden" />
    <input type="checkbox" name="mailitto[]" value="john@example.com">John</input>
    <input type="checkbox" name="mailitto[]" value="sue@example.com">Sue</input>
    <input type="checkbox" name="mailitto[]" value="andy@example.com">Andy</input>
    <input class="submit-button" type="submit" name="submit" value="Submit" /></form>

    The mailback.pl script has an required name of "mailitto" for the recipient. Did I set this up right?

  9. #9
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by svoltmer View Post
    The mailback.pl script has an required name of "mailitto" for the recipient. Did I set this up right?
    Since you are using mailback.pl, you'll need to revert the name back to "mailto" and live within the restrictions of that program.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #10
    SitePoint Member
    Join Date
    Mar 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I change the name of the input to "mailto" it will not work. It will throw an error about a missing value of "mailitto". I don't have access to the pearl script to change the required values.

    Also, how do a pull the selected email addresses out of the array and input them into the "mailto" or "mailitto" name, so that when the mailback.pl script processes the form all the selected email recipients get the form data?

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by svoltmer View Post
    If I change the name of the input to "mailto" it will not work. It will throw an error about a missing value of "mailitto". I don't have access to the pearl script to change the required values.
    Then for the perl script to work, you will need to use "mailitto"

    Quote Originally Posted by svoltmer View Post
    Also, how do a pull the selected email addresses out of the array and input them into the "mailto" or "mailitto" name, so that when the mailback.pl script processes the form all the selected email recipients get the form data?
    Since you can't edit that perl script, I don't think that there is a way to use that perl script to achieve what you desire.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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