Hi rodsdesign,
There are a few buglets in your code. I've posted a working version below but first here's the structure with some explanation. Form HTML
<?php
// test if the form has been submitted
// in your code the name of the submit button is 'undefined'
if ( $_POST['submit'] == '' ) {
// this is a new form
?>
<!-- original form code here -->
<?php
} else {
// this is the second form
?>
<!-- second form code here -->
</php
}
?>
In the Onsubmit after box
<?php
// test the submitted data
$year = date('Y');
if ( $year - $_POST['birthday_year'] >= 13 ) {
// user passed test
// this reshows the form but $_POST != "" so the second form will display
showForm($_POST);
$error_found = true;
} else {
// user failed test
?>
<!-- show a message here -->
<?php
// add a redirect in here if you like
}
?>
Notice that both sets of form code are in the form_html box. The OnSubmit after tests the reponse and redirects as needed. (I used OnSubmit after as you need to have Email on for the OnSubmit Before code to execute.
Bob
Full code- form HTML
<?php
if ( $_POST['undefined'] == '' ) {
// this is a new form
?>
<input type="hidden" id="text_10" name="text_10" value="user" />
<h3>Sign Up</h3>
<div class="form_item" >
<div class="form_element cf_textbox" >
<label class="cf_label" >Username</label>
<input class="cf_inputbox required" maxlength="150" size="30" id="text_0"
name="text_0" type="text" value="<?php echo $_POST['text_0'];?>" /></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_textbox"><label class="cf_label">Email
Address</label><input class="cf_inputbox required validate-email" maxlength="150"
size="30" id="text_3" name="text_3" type="text" value="<?php echo $_POST['text_3']; ?>" /></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_password"><label class="cf_label">Password</label><input
class="cf_inputbox required" maxlength="150" size="30" id="text_1"
name="text_1" type="password" value="<?php echo $_POST['text_1'];?>" /></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_password"><label class="cf_label">Confirm
Password</label><input class="cf_inputbox required" maxlength="150" size="30"
id="text_2" name="text_2" type="password" value="<?php echo $_POST['text_2'];?>" /></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element birthday_month"><label class="cf_label">Month
of Birth:</label> <select name="birthday_month" id="birthday_month"
);" autocomplete="off">
<option value="-1">Month:</option>
<?php
$month_array = array( 1 => 'Jan', 2 => 'Feb', 3 => 'Mar', 4 => 'Apr',
5 => 'May', 6 => 'Jun', 7 => 'Jul', 8 => 'Aug', 9 => 'Sep',
10 => 'Oct', 11 => 'Nov', 12 => 'Dec' );
foreach ( $month_array as $k => $v ) {
$selected = "";
if ( $_POST['birthday_month'] == $k ) {
$selected = "selected='selected'";
}
echo "<option $selected value='$k' >$v</option>";
}
?>
</select></div>
</div>
<div class="form_item">
<div class="form_element birthday_year"><label class="cf_label">Year
of Birth:</label> <select name="birthday_year" id="birthday_year" autocomplete="off">
<option value="-1">Year:</option>
<?php
for ($i = 2008; $i >= 1934; $i-- ) {
echo "<option value='$i'>$i</option>";
}
?>
</select></div>
</div>
<div class="form_item">
<div class="form_element cf_captcha"><label class="cf_label">Enter
captcha text</label><span> {imageverification} </span></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_button"><input value="Register"
name="undefined" type="submit"></div>
<div class="clear">Â </div>
</div>
<?php
} else {
// this is the second form
?>
<div class="form_item">
<div class="form_element cf_text"><span class="cf_text">Would you like to join
the D&J maling list? We won't spam you... but we'd love to shoot something
over every once in a while...</span></div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_radiobutton"><label class="cf_label"></label>
<div class="float_left"><input value=" yes!" class="radio" id="_yes!0"
name="radio0" type="radio"><label for="_yes!0" class="radio_label" > Yes!</label><br>
<input value=" no thanks" class="radio" id="_no thanks0" name="radio0"
type="radio"><label for="_no thanks0" class="radio_label"> No Thanks</label><br>
</div>
</div>
<div class="clear">Â </div>
</div>
<div class="form_item">
<div class="form_element cf_button"><input value="Submit" name="undefined"
type="submit"></div>
<div class="clear">Â </div>
</div>
<?php
}
?>
OnSubmit after:
<?php
$year = date('Y');
if ( $year - $_POST['birthday_year'] >= 13 ) {
echo "test 1";
showForm($_POST);
$error_found = true;
} else {
echo "test 2";
// this is a new form
?>
<p>We're really sorry but you are too young to subscribe to our list.
Please come back in a few years.</p>
<?php
// add a redirect in here if you like
}
?>