How to process the code so that after checking the radiobutton does not send to another site, but everything remains the same, that is, when you process the radiobutton, PHP automatically sends you to an empty site after processing, I also need to reload the page and deduced an error if no radio was selected, how to implement it?

HTML

<input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°1" name="radio-test"/>Π§Π΅ΠΊ бокс β„–1 <input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°2" name="radio-test"/>Π§Π΅ΠΊ бокс β„–2 <input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°3" name="radio-test"/>Π§Π΅ΠΊ бокс β„–3 

Php

 if (isset($radio) == false) { $error_radio = "Π’Ρ‹ Π½Π΅ Π²Ρ‹Π±Ρ€Π°Π»ΠΈ чСкбокс!"; 

}

  • one
    PHP does not send to another site. Everything is done by the programmer. If you need to find an error in your code, then it would be logical to bring this code - Anton Shchyrov
  • I corrected the main message, check. I need the code to not send me to another page, when I check for example type = "text" there is no such thing, just the page is updated and that's it. And then there is a referral to another page, which I do not need - Mark Minerov
  • There is no transfer in the above code - Anton Shchyrov September
  • I’m talking about too, but sends me to a blank site, like this video: youtube.com/watch?v=DmyoiloSCIg Here a person transfers to another site when he presses a button, I don’t need it, I just want PHP I have reloaded the page as needed and processed this request on this page, please note that it’s all in the form, everything is as it should be. - Mark Minerov

1 answer 1

In the video lesson to which you gave the link, these forms are sent to the process.php file. In order for the data to be sent to the same script where the form is located, you need to set the value of the action attribute of the form as an empty string.

 <form method='POST' action=''> <input type='hidden' name='send' value='1'> <input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°1" name="radio-test"/>Π§Π΅ΠΊ бокс β„–1 <input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°2" name="radio-test"/>Π§Π΅ΠΊ бокс β„–2 <input class="radio" type="radio" value="ΠΊΠΎΡ€ΠΎΠ±ΠΊΠ°3" name="radio-test"/>Π§Π΅ΠΊ бокс β„–3 <input type='submit' value='go!'> </form> <?php @$send = $_POST['send']; if ( $send ) // Ρ„ΠΎΡ€ΠΌΠ° ΠΎΡ‚ΠΏΡ€Π°Π²Π»Π΅Π½Π°? { @$radio = $_POST['radio-test']; if( !$radio ) // Ρ€Π°Π΄ΠΈΠΎΠΊΠ½ΠΎΠΏΠΊΠ° Π²Ρ‹Π±Ρ€Π°Π½Π°? { $error_radio = "Π’Ρ‹ Π½Π΅ Π²Ρ‹Π±Ρ€Π°Π»ΠΈ чСкбокс!"; echo $error_radio; } } ?>