Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Question Radio Buttons in Form Name Issue

    If I make a unique name such as field1, field 2 for the radio buttons for the form the radios don't change upon selection from one to the other. On the other hand if I give them all the same name such as "hi" the data doesn't write in the email. I can't use:
    <select name="name">Radios here</select> because the radios are not just a simple row but each have divs with table rows and fields which open below them when selected.

    This is the code that writes the data in the email:
    '.$_POST['radiofieldname'].'

    Anyone have a solution for this PLEASE?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Select != radio. Select's won't send anything back unless an <option> has been selected.
    You group your radios by providing them with the same name.

  • #3
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Select != radio. Select's won't send anything back unless an <option> has been selected.
    You group your radios by providing them with the same name.
    I'm sorry can you please clarify that in context of the code in entirety? I'm still a rookie. Thanks!:

    <input type="radio" name="hi" id="window" value="Text here." onClick="showHide('windows')" onChange="document.getElementById('showme').style.display=this.selectedIndex==0?'none':'block';"/>
    Last edited by johnwboyd; 09-07-2011 at 06:31 PM.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Code:
    <input type="radio" name="hi" id="window" value="Text here." onClick="showHide('windows')" onChange="document.getElementById('showme').style.display=this.selectedIndex==0?'none':'block';"/> 
    <input type="radio" name="hi" id="window2" value="Different Text here." onClick="showHide('windows')" onChange="document.getElementById('showme').style.display=this.selectedIndex==0?'none':'block';"/>
    Ignoring the JS, PHP will have an offset under 'hi' from _GET or _POST with a value of either 'Text here.' or 'Different Text here.' depending on what has been chosen. Radio buttons must have the same name to be treated as a group, or HTML won't know that there is a relationship between the two.

  • Users who have thanked Fou-Lu for this post:

    johnwboyd (09-07-2011)

  • #5
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Code:
    <input type="radio" name="hi" id="window" value="Text here." onClick="showHide('windows')" onChange="document.getElementById('showme').style.display=this.selectedIndex==0?'none':'block';"/> 
    <input type="radio" name="hi" id="window2" value="Different Text here." onClick="showHide('windows')" onChange="document.getElementById('showme').style.display=this.selectedIndex==0?'none':'block';"/>
    Ignoring the JS, PHP will have an offset under 'hi' from _GET or _POST with a value of either 'Text here.' or 'Different Text here.' depending on what has been chosen. Radio buttons must have the same name to be treated as a group, or HTML won't know that there is a relationship between the two.
    Yes I understand that the radio name must be the same but the problem is that the php is simply not writing in the mail and it seems to be because there is no unique name for the radio or I left something out of the php itself.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Then post the code in use including the html form to send it.

  • #7
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Then post the code in use including the html form to send it.
    It's a lot of code overall so if you don't mind I will just link to the html and php pages:

    http://voiceprocess.net/html.txt

    http://voiceprocess.net/php.txt

    Thank you!

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Quote Originally Posted by johnwboyd View Post
    It's a lot of code overall so if you don't mind I will just link to the html and php pages:

    http://voiceprocess.net/html.txt

    http://voiceprocess.net/php.txt

    Thank you!
    I will not be able to view these until after work.

  • #9
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    By the way is there a way to get the showhide to ONLY hide upon click of a check box or radio button? As one of the radios added is None of the above. If this is selected I want the address fields to hide.

  • #10
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Sure, the easiest way would be to write a function to determine what element to collapse and call it passing in the parameter using the onclick event. That is Javascript though, it has nothing to do with PHP.

  • Users who have thanked Fou-Lu for this post:

    johnwboyd (09-09-2011)

  • #11
    New Coder
    Join Date
    Feb 2008
    Posts
    54
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fou-Lu View Post
    Sure, the easiest way would be to write a function to determine what element to collapse and call it passing in the parameter using the onclick event. That is Javascript though, it has nothing to do with PHP.
    I understand the javascript side but the point is when I have the same name for the radio buttons the php doesn't write the field values in the mail. Do I have to rewrite the code in divs instead of tables for the radio grouping to work with 2 tags <select name="xyz"></select> instead of naming the radios?

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Umm, no. Back to my first post:
    Quote Originally Posted by Fou-Lu View Post
    Select != radio. Select's won't send anything back unless an <option> has been selected.
    Select has nothing to do with a radio.

    I only see two names for radios: yes, and hi. Neither of these are dealt with in the processing code, so no you won't get a display for them at all.
    I do see several unspecified fields which appear to correspond to the 'id' of the radio. These are irrelevant, id is a dom/html thing, not a PHP thing so these are not sent back from the browser. These are radios with the same name too, so you will only receive the last one selected; if you want to allow multiple you use a checkbox control as an array instead.


  •  

    Posting Permissions

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