In my site I'm using php to handle contact/subscribe. The form is quite simple, there are two radio buttons that should control whether the user wants to "subscribe" or to "contact" me. In the latter case, I would like another "Message" box to appear. This is what I have so far:
In contact.php
:
<?php include('form_process.php'); ?>
<html>
<head>
...
...
<div class="blockform">
<h2> Contact/Subscribe </h2>
<div class="container" >
<form id="contact" action="<?= $_SERVER['PHP_SELF']; ?>" method="post">
<label class="label">
<input type="radio" name="gender"
<?php if (isset($gender) && $gender=="subscribe") echo "checked";?>
value="subscribe"> SUBSCRIBE
<input type="radio" name="gender" style="margin-left:2em"
<?php if (isset($gender) && $gender=="contact") echo "checked";?>
value="contact"> CONTACT
</label>
<label class="label" for="name">Name: *</label>
<fieldset>
<input class="w-input input" placeholder="Your Name" type="text" name="name" value="<?= $name ?>" tabindex="1" required autofocus>
<span class "error"><?= $name_error ?></span>
</fieldset>
<label class="label" for="email">Email address: *</label>
<fieldset>
<input class="w-input input" placeholder="Your Email Address" type="Email" name="email" value="<?= $email ?>" tabindex="2" required>
<span class "error"><?= $email_error ?></span>
</fieldset>
<label class="label" for="field" <?php if ($gender == 'subscribe'){?>style="display:none"<?php } ?>> Message:</label>
<fieldset>
<textarea class="w-input input" <?php if ($gender == 'subscribe'){?>style="display:none"<?php } ?> id="field" placeholder="Enter your message" name="message" value="<?= message ?>" tabindex="3" required></textarea>
<button class="w-button button-link button-right" name="submit" type="submit" id="contact-submit" data-submit="Please wait...">SUBMIT</button>
<fieldset> </fieldset>
</form>
</div>
</div>
and in form_process.php
I have the usual code to handle what happens when I click the "Submit" button. The problem I have is that for the code that hides/shows the message box to work properly, the page needs to be reloaded considering the actual value of the radio button. But clicking the radio button doesn't trigger anything. I tried adding an onclick
javascript function to reload the page, but this is not considering the actual value of the radio button I pressed. This seems to be an easy problem but I can't find the solution to it.