SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Now available in Orange Tijmen's Avatar
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    1,469
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $vars from checkbox

    I have a forum which has 2 checkboxes , namely subscribe and unsubscribe. If the code is like this you can only select on of the two options.

    PHP Code:
    if (isset($unsub) == 1) { 
    and 
    if (isset(
    $sub) == 1) { 
    HTML Code:
    <tr>
    <td width="87"><INPUT TYPE=RADIO NAME="mail" VALUE="sub" />Subscribe </td>
    <td width="15" rowspan="3"><img src="../images/spcr1px.gif" width="15" height="15" /></td>
    <td width="147"><INPUT TYPE=RADIO NAME="mail" VALUE="unsub" />Unsubscribe</td>
    tr>
    But the problem is that the name should be sub and unsub so that i have two different variables which i can use in php. If i do that, then you're suddenly allowed to select both of the options which shouldn't happen. So how can i give these two fields different names/$vars while your're still able to select only one option instead of 2?

  2. #2
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they don't need different names!
    u just have to change your PHP Syntax to the following:
    PHP Code:
    if (isset($_GET['mail'])
       {
          if (
    $_GET['mail']=="sub")
               {
                  
    // do the Subscribe baby!
               
    }
           if (
    $_GET['mail']=="unsub")
                {
                   
    //unsibscribe me for gods sake!
                
    }
       } 
    u know if the name differs there is afaik no chance to group multiple radio buttons to 1 radio group with HTML, it might be done with JavaScript, but i don't know JS
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de

  3. #3
    SitePoint Addict rokc's Avatar
    Join Date
    Oct 2004
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi tijmen,

    I think its not possible to give different names to the radio button and still keep them in the same group. The only thing you have to do is to check the value of $_POST['mail'] or $_GET['mail'].

  4. #4
    SitePoint Addict rokc's Avatar
    Join Date
    Oct 2004
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i think slayman has proved the point

  5. #5
    SitePoint Enthusiast SlayMan's Avatar
    Join Date
    Oct 2004
    Location
    Germany/ Hamburg
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    :-)
    SlayMan,
    Your friendly neighbourhood trainee and webmaster
    go, see for yourself @ http://www.alpupp.de

  6. #6
    Now available in Orange Tijmen's Avatar
    Join Date
    Jul 2004
    Location
    The Netherlands
    Posts
    1,469
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works fine now, thanks...


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
  •