Skip to content

Instantly share code, notes, and snippets.

@antcms
Last active September 30, 2019 08:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antcms/5ee9f6e77a5decd8f228818f0b546afc to your computer and use it in GitHub Desktop.
Save antcms/5ee9f6e77a5decd8f228818f0b546afc to your computer and use it in GitHub Desktop.
Dynamic Registration form for WordPress Simple Membership Plugin (with Form Builder Addon). Choose Membership level from a Select Menu and div below dynamically populates with the correct form for that level. Requires jQuery. https://simple-membership-plugin.com / https://simple-membership-plugin.com/simple-membership-form-builder-addon/
<div class="registration">
<h2 class="title">Register Here:</h2>
<script type="text/javascript">
$(document).ready(function(){
var hideAll = function() {
$('div[class^=option]').hide();
}
$('#select').on('change', function() {
hideAll();
var category = $(this).val();
$('.' + category).show();
});
});
</script>
<form method="post">
<label for="option">To register start here: </label>
<select name="select" id="select">
<option value="option1">Choose your membership level&hellip;</option>
<?php
$squery = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
$levels = $wpdb->get_results($squery, ARRAY_A);
foreach ($levels as $level) {
$mlvalue = $level['id'];
$mlname = $level['alias'];
echo '<option value="option' . $mlvalue . '">' . $mlname . '</option>';
}
?>
</select>
</form>
<div class="option1" style="display:block;">
<p>To begin please select the membership level you wish to sign up for from the list above.</p>
</div>
<?php
$dquery = "SELECT * FROM " . $wpdb->prefix . "swpm_membership_tbl WHERE id !=1 ";
$levels = $wpdb->get_results($dquery, ARRAY_A);
foreach ($levels as $level) {
$mlvalue = $level['id'];
$mlname = $level['alias'];
echo '<div class="option' . $mlvalue . '" style="display:none;"><h4>' . $mlname . ' Registration</h4>' . do_shortcode('[swpm_registration_form level=' . $mlvalue . ']') . '</div>';
}
?>
</div>
@salmancth
Copy link

Its not working. Can you check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment