I’m not sure you need “ajax” per say, but certainly javascript.
What I would have do is create a page template in your theme and inthis theme, create all the forms you wish to display dynamically usingthe template tags (i.e. tdomf_the_form(id of form)). Then use a bit ofjQuery magic to hide all of them except the one you’re interested in.
…
I did a small test and managed to get it to work using a pagetemplate. This is the code I added to switch dynamically between 4different forms depending on a radio button:
You should be able to use that as a base to do more funky things.The builtin jQuery in Wordpress 2.7 allows you to do some nice stuff,like fading in and out the form. And it seems to work fine with a mixof forms using AJAX or non-AJAX too.<?php if(function_exists('tdomf_the_form')){ ?>
<script type='text/javascript' src='<?php echo get_bloginfo('wpurl'); ?>/wp-includes/js/jquery/jquery.js'></script>
<style>
#tdomf_form1 { display: none; }
#tdomf_form2 { display: none; }
#tdomf_form3 { display: none; }
#tdomf_form4 { display: none; }
</style>
<script type="text/javascript">
//< ![CDATA[
function show_form(form_id){
switch(form_id) {
case 1:
jQuery('#tdomf_form2').css("display", "none");
jQuery('#tdomf_form3').css("display", "none");
jQuery('#tdomf_form4').css("display", "none");
jQuery('#tdomf_form1').css("display", "block");
break;
case 2:
jQuery('#tdomf_form1').css("display", "none");
jQuery('#tdomf_form3').css("display", "none");
jQuery('#tdomf_form4').css("display", "none");
jQuery('#tdomf_form2').css("display", "block");
break;
case 3:
jQuery('#tdomf_form1').css("display", "none");
jQuery('#tdomf_form2').css("display", "none");
jQuery('#tdomf_form4').css("display", "none");
jQuery('#tdomf_form3').css("display", "block");
break;
case 4:
jQuery('#tdomf_form1').css("display", "none");
jQuery('#tdomf_form2').css("display", "none");
jQuery('#tdomf_form3').css("display", "none");
jQuery('#tdomf_form4').css("display", "block");
break;
default:
alert("ERROR: show_form: Unknown Form ID");
break;
}
}
//-->
</script>
<?php if(tdomf_can_current_user_see_form(1)) { ?>
<input type="radio" name="dynamic_forms" id="dynamic_forms_1" onChange="show_form(1);">
<label for="dynamic_forms_1">Form 1</label><br/>
<?php } ?>
<?php if(tdomf_can_current_user_see_form(2)) { ?>
<input type="radio" name="dynamic_forms" id="dynamic_forms_2" onChange="show_form(2);">
<label for="dynamic_forms_2">Form 2</label><br/>
<?php } ?>
<?php if(tdomf_can_current_user_see_form(3)) { ?>
<input type="radio" name="dynamic_forms" id="dynamic_forms_3" onChange="show_form(3);">
<label for="dynamic_forms_3">Form 3</label><br/>
<?php } ?>
<?php if(tdomf_can_current_user_see_form(4)) { ?>
<input type="radio" name="dynamic_forms" id="dynamic_forms_4" onChange="show_form(4);">
<label for="dynamic_forms_4">Form 4</label><br/>
<?php } ?>
<?php if(tdomf_can_current_user_see_form(1)) tdomf_the_form(1); ?>
<?php if(tdomf_can_current_user_see_form(2)) tdomf_the_form(2); ?>
<?php if(tdomf_can_current_user_see_form(3)) tdomf_the_form(3); ?>
<?php if(tdomf_can_current_user_see_form(4)) tdomf_the_form(4); ?>
<?php } ?>
联系客服