• Hi,
    Making a new post so as not to mix topics up…

    I know you have options for unlimited or single submission forms…

    I would like to be able to assign a defined amount of submissions, say, once 5 people have answered this form, the form is considered completed, and the posts containing this form would be marked as private, or whatever.

    Is there any way to do this?

    Thanks!!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author hoffcamp

    (@hoffcamp)

    There isn’t an easy way to do this, but you mentioned in the other post about actions, and this is something I have been meaning to do but have not. What exactly do you need to tie into?

    Thread Starter lilireed

    (@lilireed)

    Hi hoffcamp, thanks for the interest!

    Here’s what I’m trying to do. The webpage should grant users points for every form they submit. I’ve got posts set up, each with a different form in it, for example asking for an opinion on a certain product. Each post has a custom field, named “points” that assigns a number of points the submission is “worth”. Also, if I need 5 opinions, I would like the post to “expire” after the 5th user completes the form.

    So, say, user x sees a post, sees it’s worth 45 points, completes a form and submits it. What I want to accomplish is that when he submits the form, 45 points are added to his “acount” and there is one less chance to complete the form for another user, and now (if originally I wanted 5 opinions) there would be only 4 submissions left to complete before the post turns private or whatever.

    I found the Cubepoints plugin, that works pretty well but only assigns points to users for registering or adding comments, which I am not interested in… but if I could somehow create a new module for it that would assign the points in the form to the user in the Cubepoints table, that would be great!

    Wow that was long, was that what you were asking? It’s like two things put together…

    Any direction will be greatly appreciated! completely stuck…

    Plugin Author hoffcamp

    (@hoffcamp)

    Sorry I’ve been out of town – I’ll add an action hook for form submission that includes the posted data and information about the current form. I think you mentioned in another post that you wanted something like that, so I’m assuming you are comfortable with PHP & MySQL? That is really the only way I can see this working.

    Plugin Author hoffcamp

    (@hoffcamp)

    I added an action hook, ‘fm_form_submission’, which is called after a form has been submitted, and after the data has been submitted to the database and e-mails are sent. The action function should take a single array as an argument. You should do a print_r of the array to see what you have access to; the top level of the array has two keys, ‘form’ and ‘data’. The ‘form’ key gives you all of the information about the current form stored in the database, and the ‘data’ key is an array containing the processed submission data. You can access the individual form items in the ‘data’ array by their nicknames, if they have them.

    If you have any questions, feel free to ask! I have been out of town for the past few days, so I’ll be around to answer questions faster now.

    Thread Starter lilireed

    (@lilireed)

    thanks so much, this will certainly come in handy… I didn’t quite grasp everything you wrote because I’m not at all comfortable with PHP and MySQL… ?? But thanks to your update I was able to find the file in which all these post submit commands are to figure out how to add points (yeah, I couldn’t figure that one out).

    Just so you know, here’s what I did:

    The CubePoints plugin has hooks to add points for different actions a user may do, like for example posting a comment. So I copied this line of code from the hook in cp_points.php:

    cp_points('comment', cp_currentUser(), apply_filters('cp_comment_points',get_option('cp_comment_points')), $cid);

    and copied it into your API.php file after where you included the fm_form_submission action.

    So now, Every time a form is submitted, the default amount of points that I set for comments in the CubePoints configuration page will be added to the user account.

    In cp_hooks.php I commented out all the lines that added points for registering, adding posts… ect because I didn’t want users to add points for these actions.

    To further customize this, I added the “custom points” module to CubePoints, that allows you to add a specific amount of points for comments to any particular post. So if I give the submission of a form in a certain post 45 points, when the person submits it, 45 points will be added.

    Works like a charm!!

    Anyway, being able to access the data you mentioned above will be great.

    I’ll let you know when I’ve put the page online, so you can see what I’m talking about if it sounds like jibberish!

    Thanks,

    Lili

    Plugin Author hoffcamp

    (@hoffcamp)

    Lili, you make perfect sense, but what you did is going to prevent you from updating the plugin, since every file is completely rewritten each time, or at least force you to redo the changes you made after each update. Instead I would make a new directory in /wp-content/plugins, something like ‘fm-cp-integration’, and then make a file within that folder, ‘fm-cp-integration.php’, and put the following code in:

    <?php
    /*
    Plugin Name: Form Manager Custom Submission Action
    Description: (your description here)
    */
    
    add_action( 'fm_form_submission' , 'fm_cp_submission_action' );
    function fm_cp_submission_action($args){
    	(your code here)
    }
    ?>

    Then just paste whatever code you want to attach to form submission within the function body.

    The plugins section will now show a ‘Form Manager Custom Submission Action’ plugin. Activate it and you should be all set. This way you won’t have to worry about updates obliterating your changes.

    Plugin Author hoffcamp

    (@hoffcamp)

    I put the same code (with some extra comments) into a zip file just in case you are having problems. And so somebody else can use it.

    Thread Starter lilireed

    (@lilireed)

    Thanks!
    I did just that, now there′s no fear of upgrades! ??

    About the specific amount of submissions, though, do you have any ideas?

    This is what I’d asked before:
    I would like to be able to assign a defined amount of submissions, say, once 5 people have answered this form, the task is considered completed, and the post containing this form would be marked as private.

    There′s a plugin I’m using to mark posts as private after a certain date, Content Scheduler… I imagine I could see if I can do something similar to what we did with the points, and I should add some code to retrieve the number of submissions allowed… (of course first I would have to set it!! ha). Where would you do this?

    Thanks sooo much for all the help!

    Lili

    PD: Here’s the Content Scheduler code I’ll try to fit in to expire the post on the “nth” submission:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Plugin Author hoffcamp

    (@hoffcamp)

    WordPress has a mechanism to store ‘option’ values in PHP, update_option() and get_option(). You could use those functions in conjunction with the form ID to get and set a value specific to that form, in your case the number of submissions. You would have to add them to the appropriate action hooks, and you might also want to have a way of checking how many submissions remain. You can add code to the ‘custom submission plugin’ file that you downloaded to do these things rather than create a new plugin. The plugin API reference is a good place to start on how to modify wordpress to do what you are asking.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Specific amount of submissions?’ is closed to new replies.