www.webdeveloper.com
Results 1 to 5 of 5

Thread: Radio buttons not working

  1. #1
    Join Date
    Dec 2011
    Location
    Bucharest Romania
    Posts
    40

    Radio buttons not working

    I have a form with 12 checkboxes, one group of radio buttons with two members - group1, and another group with 4
    members - group2

    I send the chosen values using post.

    Checkboxes and group1 work fine, but when I introduce group2 php sees it as an array, unlike group 1.

    In other words:

    if (isset($_POST['submitted'])) {
    $word=$_POST['word'];
    $group1=$_POST['group1'];
    $group2=$_POST['group2'];

    foreach($_POST['tenses'] as $tense) {
    if ($group1=="activ"){
    ...
    }else if ($group1="pasiv"){
    ...
    }
    }
    }
    works
    but

    if (isset($_POST['submitted'])) {
    $word=$_POST['word'];
    $group1=$_POST['group1'];
    $group2=$_POST['group2'];

    foreach($_POST['tenses'] as $tense) {
    echo $group2;
    if ($group2=="afirmativ"){
    if ($group1=="activ"){
    ...
    }else if ($group1="pasiv"){
    ...
    }
    }
    }
    }
    does not.
    Instead of printing a value as for $group1, the echo prints 'Array'.

    Why could that be, I am doing the same thing for both sets of radio buttons.
    Thanks

  2. #2
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Can you show the form you're using? My guess is there's [] on group 2, or something along those lines.

  3. #3
    Join Date
    Dec 2011
    Location
    Bucharest Romania
    Posts
    40
    Well, here is the whole form, I checked it and rechecked it (even for array brackets).

    <h4><?php echo $page_title; ?></h4>
    <form action='<?php echo $php_action;?>' method="post">
    <table cellpadding="5"><tr><td>Verb:</td><td><input name="word" type="text" size='20' /></td></tr>
    <tr><td><input type="radio" name="group1" value="activ" checked="yes"/>Diateza activa</td><td><input type="radio" name="group1" value="pasiv"/>Diateza pasiva</td></tr>
    <tr><td><input type="radio" name="group2" value="afirmativ" checked="yes"/>Afirmativ</td><td><input type="radio" name="group2" value="negativ"/>Negativ</td><td><input type="radio" name="group2" value="interogativ"/>Interogativ</td><td><input type="radio" name="group2" value="interogativ_negativ"/>Interogativ negativ</td></tr>
    <tr><td><input type="checkbox" name="tenses[]" value="present"/> Prezent (Present Tense)</td><td><input type="checkbox" name="tenses[]" value="past"/> Trecut (Past Tense)</td><td><input type="checkbox" name="tenses[]" value="future"/> Viitor (Future Tense)</td></tr>
    <tr><td><input type="checkbox" name="tenses[]" value="present2"/> Prezent Continuu</td><td><input type="checkbox" name="tenses[]" value="past2"/> Trecut Continuu</td><td><input type="checkbox" name="tenses[]" value="future2"/> Viitor Continuu</td></tr>
    <tr><td><input type="checkbox" name="tenses[]" value="present3"/> Prezent Perfect</td><td><input type="checkbox" name="tenses[]" value="past3"/> Trecut Perfect</td><td><input type="checkbox" name="tenses[]" value="future3"/> Viitor Perfect</td></tr>
    <tr><td><input type="checkbox" name="tenses[]" value="present4"/> Prezent Perfect Continuu</td><td><input type="checkbox" name="tenses[]" value="past4"/> Trecut Perfect Continuu</td><td><input type="checkbox" name="tenses[]" value="future4"/> Viitor Perfect Continuu</td></tr>

    </table><br><hr><br>
    <p><input type="hidden" name="submitted" value="1"></p>
    <p><input type="submit" value="Trimite" /></p>
    </form>

  4. #4
    Join Date
    Oct 2010
    Location
    Ohio
    Posts
    233
    Hmmm, well hopefully someone else can find a "Logic in Your Flaw"(tm) because given the php and form I don't see any reason an array would exist for either radio button. sorry.

  5. #5
    Join Date
    Dec 2011
    Location
    Bucharest Romania
    Posts
    40
    I solved it, sort of.
    If I put $group2[0] it posts the checked radio button...
    Last edited by arrowthesparrow; 11-13-2012 at 09:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles