WordPress.org

Support

Support » Plugins and Hacks » [Plugin: Contact Form 7 to Database Extension] Database entries

[Plugin: Contact Form 7 to Database Extension] Database entries

Viewing 15 replies - 1 through 15 (of 21 total)
  • I am sorry this is for contact forms. Forgot to mention that

    Plugin Author Michael Simpson
    Participant

    @msimpson

    This plugin does not support that. But when a file is uploaded, it is temporarily saved in the file system. This plugin copies that into the DB. But after that usually the file gets deleted, not but this plugin, but by Contact Form 7 if you use that. So you might see if there is a way to configure CF7 to save the upload somewhere.

    jalabiso
    Member

    @jalabiso

    kbarlow have you find any solution on this? I am looking for the same

    jalabiso
    Member

    @jalabiso

    bytheway Micheal,

    I think the ‘storing’ part of the job is (at least at the current form) of your plugin, as CF7 orginally is not designed to store anything but just to send.
    Your plugin instead is the one doing the ‘saving’ now: it gets into the process of CF7, gets the file from TEMP and store it into DB before CF7 deletes it.

    I guess at that point you could decide whether to store it direcly in DB (as you do now) or save it to some dir, saving into DB only its path.

    I hope you don’t take this personally. I deeply respect your work and I am just trying to give a suggestion

    keepitup!

    Plugin Author Michael Simpson
    Participant

    @msimpson

    The way to accomplish this is follow the instructions here to intercept the form when it is about to be saved, then store the file where you like.

    euchapelice
    Member

    @euchapelice

    hi

    i hope you could help, i’ve tried some filtering of my own

    first, i disabled cf7’s “auto” delete attachment (instructions above). then, on instructions from the linked page, i tried adding a field that would contain the cf7 temp dir plus the filename of the attachment, like putting in the database the url instead of the file itself:
    (cf7 temp dir) + filename = url of attachment

    finally, i tried to unset the original field that i thought contained the file (that would be put in the database):
    unset($formData->posted_data['myform-attachment']);

    i even tried to unset ‘uploaded_files’:
    unset($formData->uploaded_files['fileupload']);

    but my understanding of wp, php and the plugin reached their limit. so my question is: how do i unset or delete the file that’s included in the database? so that i’ll end up only with the file in the cf7 temp dir and only the url in the database?

    thank you very much! and thank you for this great and awesomely useful plugin!

    Plugin Author Michael Simpson
    Participant

    @msimpson

    I think you are almost there. Assuming the form’s field name for the file upload is “myform-attachment” I think what you need to do is:

    unset($formData->posted_data['myform-attachment']);
    unset($formData->uploaded_files['myform-attachment']);
    euchapelice
    Member

    @euchapelice

    thank you! will try this. once i get this part working, on to the next step: attachment moving (to permanent dir) plus renaming (to avoid overwrites when uploads have the same filename)

    euchapelice
    Member

    @euchapelice

    hello again michael, i was able to try the code you provided, and i was able to save the attachment in the temp dir and store only the link in the database. unfortunately, when i received the test email sent by cf7, there was no attachment. my question is, does the filtering in function.php (for cf2db extension) happen before cf7 sends the form to the recipient email? (thus, attachment gets deleted before it is sent)
    – cf7 form
    – form is filled and processed
    – cf2db gets data and puts these to db
    – cf7 sends form to recipient

    is this the reason why no attachment was sent?

    thanks!

    Plugin Author Michael Simpson
    Participant

    @msimpson

    my question is, does the filtering in function.php (for cf2db extension) happen before cf7 sends the form to the recipient email? (thus, attachment gets deleted before it is sent)

    You are correct. I didn’t consider that. That implies you should not unset the variables.

    euchapelice
    Member

    @euchapelice

    ok, thanks for the quick reply! i’ll look into other possible solutions. and share any progress.

    thanks again

    Plugin Author Michael Simpson
    Participant

    @msimpson

    If you are copying the file to a permanent location, you might simply not unset those variables but add a new variable that references the new file URL

    $formData->posted_data['different-name-attachment'] = 'http://your-site.com/path/to/file';

    euchapelice
    Member

    @euchapelice

    thanks, my first step had something similar. i think i hit a snag where the table/database of cf7todb adds a link of the attachment (a link to the database “blob”) to the value of the form-attachment field. i am trying another way, am i correct to think that if i can keep the filename (like, “upload.pdf”) without the link part, the database will also not save the blob part? i think saving the attachment part is ok (through commenting out some codes in cf7), the hard part is ‘detaching’ the blob from “wp_cf7dbplugin_submits” without deleting it before it gets sent by cf7 =)

    Plugin Author Michael Simpson
    Participant

    @msimpson

    Let me take a step back. Does your filter receive a copy of the form data:
    function myFilter($formData)

    or a reference to it (using “&” notation):
    function myFilter(&$formData)

    because something doesn’t make sense here.

    If you use the first form (I figure you probably are), then this filter gets a copy or that data which you can modify and return to CFDB for storing the data, but the CF7 plugin should retain its original unchanged copy. CF7 should then send its email using the original copy and you should still have your attachment (unless you deleted the temp file, which I assume you didn’t).

    So I don’t see why you would have any issue unset’ing variables or otherwise manipulating $formData in the filter.

    Am I missing something?

    euchapelice
    Member

    @euchapelice

    hi michael, here is the code i added to my function.php (after i comment out the lines in cf7 code, prev):

    function cfdbFilter($formData){
        $formName='Dummy form';
        $uploaddir='http://localhost/smc/wp/wp-content/uploads/wpcf7_uploads'; // note: modify htaccess of "wpcf7_uploads"
        if($formData && $formName == $formData->title){
            $formData->posted_data['form-attachment']=$uploaddir.'/'.$formData->posted_data['form-file'];
            unset($formData->posted_data['form-file']);
            unset($formData->uploaded_files['form-file']);
        }
        return $formData;
    }
    add_filter('cfdb_form_data','cfdbFilter');

    a different approach:
    also, i looked at the code of both plugins, trying to see where the ‘write to db’ happens (and also the ‘send’, in the case of cf7). and as with the previous instructions, i commented out code in cf7 and i also tried to comment out this part of “CF7DBPlugin.php”:

    if ($filePath) {
        /*$content = file_get_contents($filePath);
        $wpdb->query($wpdb->prepare($parametrizedFileQuery,
                                    $content,
                                    $time,
                                    $title,
                                    $nameClean,
                                    $valueClean));*/
    }

    (lines 520 to 528)

    and

    if (!in_array($field, $foundUploadFiles) && $filePath) {
        /*$fileName = basename($filePath);
        $wpdb->query($wpdb->prepare($parametrizedQuery,
                                    $time,
                                    $title,
                                    $field,
                                    $fileName,
                                    $order++));
        $content = file_get_contents($filePath);
        $wpdb->query($wpdb->prepare($parametrizedFileQuery,
                                    $content,
                                    $time,
                                    $title,
                                    $field,
                                    $fileName));*/
    }

    (lines 536 to 551)

    finally, for the filter in function.php, i just added the path to “form-file” and did not unset anything.

    the result is my desired effect, except of course, it is “ugly” since it tinkers directly with the code of both plugins. i was able to save the attachment from the cf7 form in the filesystem, save the path (and not the file itself) to the cfdb table, and also receive the attachment in the test email.

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘[Plugin: Contact Form 7 to Database Extension] Database entries’ is closed to new replies.