0

so.. I'm facing a problem with dynamic form/$_POST... I need to echo the image i selected via radio button in the if(isset($_POST['Submit_bc3']))... But it's not working, I don't get it.. How can i make this problem go away? Code:

<?php
    $image_url = $user['image_location'];
    $directory2 = "../../../login_/assets/playercards/";
    $images2 = glob($directory2 . "*.jpg");
    if (isset($_POST['Submit_bc3'])) {
       echo $image2;
    }else{
       foreach($images2 as $image2)
    {
    echo '<img src="'.$image2.'" border="0" height="81px" width="156px" />';
    echo "<input type='Radio' name='".$image2."' value=''></input>";
    }
    }
?>



<button type="submit" class="button" name="Submit_bc3" data-bind="vortexExternalLinkAction: ''">_LETS_GO</button>
4
  • Where do you set the first $image2? Commented Dec 24, 2013 at 11:07
  • 4
    Your radio buttons don't make sense, each of them has a different name. All the buttons in a radio button group have to have the same name. The differences should be in the value. Commented Dec 24, 2013 at 11:09
  • You should give as @Barmar said, a unique name to every radio and in the value attribute you set the image name, so you can get it when you submit. Commented Dec 24, 2013 at 11:11
  • Aye, but I don't know how excatly to get away without radio button... Commented Dec 24, 2013 at 11:11

2 Answers 2

1

You need to give all the buttons the same name so they'll be a single radio button group. Then you use that name in $_POST to get the value after submission.

if (isset($_POST['Submit_bc3'])) {
    echo $_POST['image2'];
}else{
    foreach($images2 as $image2)
        {
            echo '<img src="'.$image2.'" border="0" height="81px" width="156px" />';
            echo "<input type='Radio' name='image2' value='".htmlentities($image2)."'></input>";
        }
}
Sign up to request clarification or add additional context in comments.

Comments

1

$image2 doesn't exist in the code before you echo it after checking whether the variable in POST isset.

1 Comment

Do you have any idea how could I change it? A little snippet?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.