In PHP, I want to check if the radio buttons are checked; I do this with isset, but something isn't working.
html:
<form action="test.php" method="post" name="form_contribute" id="form_contribute">
<fieldset>
<legend>Required information</legend>
<p>Type of publication</p>
<div id="radio_buttons">
<label for="p_book">Book</label>
<input type="radio" name="p_radio" id="p_book" value="p_book">
<label for="p_article">Article</label>
<input type="radio" name="p_radio" id="p_article" value="p_article">
<label for="journal">Journal</label>
<input type="radio" name="p_radio" id="p_journal" value="p_journal">
</div>
<div id="contribute">
Title <input type="text" name="quote_title" id="quote_title">
Author(s)* <input type="text" name="author" id="author">
Title <input type="text" name="title" id="title">
ISBN <input type="text" name="isbn" id="isbn">
Publisher <input type="text" name="publisher" id="publisher">
Source <input type="text" name="source" id="source">
Addendum <textarea id="addendum"></textarea>
<div id="instructions">
<ul>
<li>Add only published non-fiction works; </li>
<li>Fill in all the required fields (designated by an asterix at the end);</li>
<li>Write the ISBN without space or special characters; if no ISBN, use identifier code as replacement;</li>
<li>Title should be written in English; exceptions are made for works unpublished in English;</li>
<li>Publisher should be the publisher of where your source derives from, not the original publisher of the work;</li>
<li>Source is to be used for verification; add chapter, section, page;</li>
<li>Use addendum to add other relevant info (e.g. if you've translated the material yourself; if the author is anonymous;) </li>
</ul>
</div> <!-- end #instructions -->
</div>
</fieldset>
<div class="big_button">
<input type="submit" name="edify_button" id="edify_button" value="Edify">
</div>
</form>
in php:
error_reporting(E_ALL); ini_set('display_errors', 'On');
if (isset($_POST['edify_button']) && isset($_POST['p_radio'])) {
$radio_values = $_POST['p_radio'];
if ($radio_values) {
echo 'checked';
}else {
echo 'unchecked';
}
}
I've also tried with !empty($_POST['my_radio']
. I don't get any errors, just a blank page. In the if-statement, in a different test, I added that if $radio_values == null
, then something, but that doesn't help either. Is there a value for checked, in php, that I'm unaware of?