• Resolved gareth94

    (@atebol)


    I’m using the following code to save the contents of my HTML element into my hidden field. However, clicking Submit on the form only submits the shortcode itself ({filter_cm_tooltip_parse}) to the database and not the selected value of the select field generated in the shortcode?

    // Render shortcode on HTML fields
    add_filter( 'forminator_replace_variables', 'do_shortcode' );
    // Include shortcode output to hidden field
    add_filter( 'forminator_custom_form_submit_field_data', function( $field_data_array ){
        
        $form = array(
            'field' => 'hidden-1', // Form hidden field
            'shortcode' => '{filter_cm_tooltip_parse}' // Shortcode to be rendered
        );
    
        foreach( $field_data_array as &$field_single ){
            if( $field_single['name'] === $form['field'] ){
                $field_single['value'] = strip_tags( do_shortcode( $form['shortcode'] ) );
            }
        }
    
        return $field_data_array;
    });
Viewing 11 replies - 16 through 26 (of 26 total)
  • Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @atebol,

    Since we haven’t heard from you for a while. I’ll mark this thread as resolved for now. Please feel free to re-open the thread if you need further assistance.

    Best Regards
    Nithin

    Thread Starter gareth94

    (@atebol)

    Apologies @wpmudev-support8 for my slow response. I’m afraid I tried your code but I get ‘No results found’ showing on the select field? I’ve included here my latest PHP file. I’ve only included 1 select field to make troubleshooting easier. If we can get that 1 field working as expected, I will then replicate it for the other select fields.

    Any help would be greatly appreciated! Thank you

    • This reply was modified 3 years, 2 months ago by gareth94.
    • This reply was modified 3 years, 2 months ago by gareth94.
    Plugin Support Laura – WPMU DEV Support

    (@wpmudev-support8)

    Hi @atebol

    Thanks for response!

    Please try slightly different version of the code:

    https://pastebin.com/WKA2nR2T

    I think this should work though I wasn’t able to test directly due to it having to connect to external DB. Note: I hope I didn’t leave any syntax error there but you may need to double-check (or just watch error log in case there were slight errors). Don’t hesitate to let us know in case you weren’t able to handle them – we’ll assist of course.

    Best regards,
    Adam

    Thread Starter gareth94

    (@atebol)

    Thank you for your response @wpmudev-support8 but I still get ‘No results found’ on the select box 🙁 I seem to get this error on the console: https://pasteboard.co/iREQXzr0Q2nu.png

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @atebol,

    The screenshot that you have shared in general shouldn’t be causing an issue with the given PHP snippet.

    I’m afraid, we’ll need to troubleshoot the given code part by part in order to rule out what might be causing.

    However, I tried to test the last snippet we shared but I’m having difficulty with making it work on my side.

    So I would like to take a step back and try the snippet which you previously tested ie here:
    https://drive.google.com/file/d/1NVI2GpHEX-G234JBdyqem2OaPGWHhadr/view?usp=share_link

    The above snippet when tested does work in my test site.

    There could be a number of use cases for the code to not work, to start with we would like to rule out whether the issue isn’t due to the incorrect DB queries in your code.

    Could you please confirm whether it works fine if you try passing an array instead of the DB query in the code snippet?

    That’s please check and see whether the following snippet works or not out of the box.

    https://pastebin.com/BNkeJ1N9

    The above code is tweaked from the code you have shared from your Google Drive.

    Where the following lines for the DB queries:

    $conn = new mysqli('SERVERIP', 'USERNAME', 'PASSWORD', 'DBNAME') or die ('Cannot connect to db');
    
    $result = $conn->query("SELECT wdt_ID, clientname FROM wp_wpdatatable_2 ORDER BY clientname ASC");

    Are replaced with an array, so that the data from the array would get populated.

    The above should help in ruling out whether the snippet works out of the box or not.

    If the abve works fine then I’m afraid the issue might have to do with how you are calling the queries from the database.

    Could you please check and see how that goes? Please do make sure the following line in the given snippet in updated to your form ID:

    private $form_id    = 14539;

    You can add the code as a mu-plugins. Please do let us know how that goes.

    Kind Regards,

    Nithin

    Thread Starter gareth94

    (@atebol)

    @wpmudevsupport11

    Apologies for my slow reply Nithin! I’m making progress! I’ve been able to get this code working (https://pastebin.com/aX8dV0eQ). The SQL results display correctly in the select box. However, when I click submit on the form itself, I get the error Selected value does not exist.appear under the Client select field?

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @atebol,

    Sorry for the delay regarding this. I gave a quick test with the previous code and could notice it does work out of the box and wasn’t able to replicate such an error.

    Seems like the error is more specific to how you are currently called the DB queries.

    I’m afraid, it’ll require a bit more time to go through your code to see what could be suggested. We’ll keep you posted once investigated asap.

    Kind Regards,

    Nithin

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @atebol,

    We tested this out and the following should work fine:
    https://pastebin.com/DbKP6Ws8

    Could you please check and see how the above snippet behaves? The above should populate all the 4 select fields. So please do make sure the DB queries are correct for the rest of the 3 select fields.

    You can also test the following which populates from the wp_posts table as example:
    https://pastebin.com/d6GDErMH

    So that you could compare and see whats being missed.

    I tested in my test server and I’m not able to find any issues with submissions.

    Please do check and see how it goes.


    Kind Regards,

    Nithin

    Thread Starter gareth94

    (@atebol)

    Hi Nithin (@wpmudevsupport11)

    Thank you so much for your time and persistence with this! The code displays and submits the data correctly for select boxes 4, 5 and 6 but not 3 (clientname) for some reason? Also, instead of submitting the selected data to the Forminator table, can the data be saved to my own custom table?

    Thank you again

    • This reply was modified 3 years, 1 month ago by gareth94.
    • This reply was modified 3 years, 1 month ago by gareth94.
    Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @atebol,

    I hope you are doing well today!

    This issue has been flagged to our SLS (Second Line Support) Team so that they can dig into this further. We will post an update here as soon as more information is available.

    Please keep in mind that our SLS Team deals with more complicated issues, so it may take a little longer for them to reply here.

    Thank you for your patience while we look into this further.

    Kind regards,
    Zafer

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @atebol,

    The code displays and submits the data correctly for select boxes 4, 5 and 6 but not 3 (clientname) for some reason? 

    Did you just copy paste the given code in the pastebine exactly as shared before? Seems like there is a minor correction in the given code here:
    https://pastebin.com/DbKP6Ws8

    There are references to two $results variables in the given code:

     $result = $conn->query("SELECT ID, post_title FROM wp_posts ORDER BY ID ASC");
                
     $result = $conn->query("SELECT wdt_ID, clientname FROM wp_wpdatatable_2 ORDER BY clientname ASC");

    The 1st line in the above is incorrect and is calling from wp_posts and should be removed. Maybe that was the case? It was more of a mistake on my side in the pastebin code, sorry about that.

    If you still have issues even after making the above changes, then would highly recommend whether the query used is correct or not.

    Please do let us know how that goes.

    Kind Regards,

    Nithin

Viewing 11 replies - 16 through 26 (of 26 total)

The topic ‘Saving user selection from HTML shortcode to database’ is closed to new replies.