WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Giving unique value to seperate radio button options (14 posts)

  1. flight118
    Member
    Posted 3 years ago #

    Hi all,

    I have a script that reads values from radiobuttons and uses these values to calculate a quote on a form.

    These values are read from the VALUE attribute of a radiobutton option.

    How can I give a radiobutton with several options a unique value to EACH option?

    Hope you guys can help me :)

    Thanks!

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    Each radio button has unique value in nature, doesn't it?

  3. flight118
    Member
    Posted 3 years ago #

    True, but Contact Form 7 set the value similar to the option name. And that is a string containing letters like this:

    <input class="radio_toggle" type="radio" name="service" value="option 1" />option 1
    <input class="radio_toggle" type="radio" name="service" value="option 1" />option 2

    What I want, is to change these unique values to make it possible to perform calculations with them, like such:

    <input class="radio_toggle" type="radio" name="service" value="100" />option 1
    <input class="radio_toggle" type="radio" name="service" value="200" />option 2
  4. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    No, it's not the correct output from Contact Form 7. If you surely use Contact Form 7, you should see this type of output:

    <span class="wpcf7-form-control-wrap radio-123">
    <span class="wpcf7-radio">
    <span class="wpcf7-list-item">
    <input type="radio" name="radio-123" value="100" />
    &nbsp;<span class="wpcf7-list-item-label">100</span>
    </span>
    <span class="wpcf7-list-item">
    <input type="radio" name="radio-123" value="200" />
    &nbsp;<span class="wpcf7-list-item-label">200</span>
    </span>
    </span>
    </span>
  5. flight118
    Member
    Posted 3 years ago #

    I think there's some miscommunication going on...

    What I showed was an example of how Contact Form 7 handles VALUES of radiobuttons. Contact Form 7 sets the value of the radiobutton EXACTLY the same as the name of the option...

    If I call my radio button: option_1
    The value will be: option_1

    I want to change that!
    I want to call my radiobutton: option_1
    and set the value to a number: 100

    The name is for the website visitor to see, the value is for me to perform calculations with. If the value is called option_1, I can't use that for any calculation of course :)

    I need to define them seperately... is this possible?

  6. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    It's not correct. Try this tag in your form

    [radio radio-123 "100" "200"]

    You'll just get what I wrote.

    How did you set your radio buttons?

  7. flight118
    Member
    Posted 3 years ago #

    I'm sorry, but that's not what I mean. I know that the radio button is supposed to do that, but I don't want that :)

    If I make a radio button like this:
    [radio radio-123 "100" "200"]

    The visitor will see a radio button with the values 100 and 200... Which doesn't make sense to him!

    I want the radio button to DISPLAY a text at every option but have a DIFFERENT VALUE in the background...

  8. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    Ok, that makes sense. See this doc. It will help.
    Selectable Recipient with Pipes

  9. flight118
    Member
    Posted 3 years ago #

    That looks great, I'm going to try that :)

    Thanks a lot Takayuki Miyoshi!

  10. flight118
    Member
    Posted 3 years ago #

    hmm, it doesn't seem to work.

    I make the code in Contact Form 7:
    [radio pages class:radio_toggle "1 to 10 pages|200" "11 to 20 pages|300"]

    And the result in the page is:

    <input type="radio" name="pages" value="1 to 10 pages" />&nbsp;<span class="wpcf7-list-item-label">1 to 10 pages</span></span><span class="wpcf7-list-item"><br />
    <input type="radio" name="pages" value="11 to 20 pages" />&nbsp;<span class="wpcf7-list-item-label">11 to 20 pages</span></span></span></span>

    It doesn't seem to work... Am I doing something wrong?

  11. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    It works correctly. They are shown as "1 to 10 pages" and "11 to 20 pages" in form HTML, then converted to "200" and "300" when you see them in mail.

  12. flight118
    Member
    Posted 3 years ago #

    Al right, that's clear. But I need the value in the HTML. The Javascript uses the values to calculate instant prices.

  13. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 3 years ago #

    If so, you don't need to use Contact Form 7's tags, just put HTML <input> tag into the form instead.

  14. flight118
    Member
    Posted 3 years ago #

    Yeah that should work.
    Thanks for helping me :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic