I have the following PHP code which is a template page for a wordpress site:

Template Name: Calculator Form
get_header(); ?>

<div id="content" class="grid_7 suffix_1 <?php echo of_get_option('blog_sidebar_pos') ?>">
<FORM action="<?php bloginfo('template_directory'); ?>/function.php" method="post">
    <INPUT TYPE="text" NAME="inputbox" VALUE="" style="width:200px;" />
    <INPUT TYPE="button" NAME="button" Value="Calculate" style="width:200px;" />
    <INPUT TYPE="text" NAME="result" VALUE="" disabled style="width:200px;" />
<?php get_sidebar(); ?>
<?php get_footer(); ?>

For arguments sake, let's say that the function.php file looks like:

    function calculate($value)
        return $value / 1000;

I want to add the result of this function into the result field in the form.

  • I think you are looking for this: wordpress.stackexchange.com/a/108145/21376 – s_ha_dum Aug 13 '13 at 23:27
  • I know some PHP, but I haven't worked with AJAX yet. If you could post the code I should use I will be very grateful. – GregoryHouseMD Aug 13 '13 at 23:33
  • Follow the link. I have basically posted the code just swap out the PHP in the callback and make sure you Javascript adds data where you want it. – s_ha_dum Aug 13 '13 at 23:35
  • I think I'm almost there. Where do I add the add_action calls? In the template file, or the function file? The JavaScrit goes in the template file I assume? – GregoryHouseMD Aug 13 '13 at 23:51
  • 1
    All of the PHP would go in functions.php or in a plugin file. The Javascript would be in a .js file of your creation. – s_ha_dum Aug 13 '13 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.