• Resolved polistus

    (@polistus)


    Hi!

    I’m working with your awesome API for the plugin. Really useful! I’m trying to update a Name field.

    Can you provide an example of how to construct correct entry meta data for the Name field that I could use for the update_form_entry() API method?

    For simple text fields, this would work just fine:

    $entry_meta = array(
    				
    				array(
    					'name' => 'text-1',
    					'value' => 'new value'
    				)
    );

    Name fields, however, are more complex. I have to update something like this:

    [meta_data] => Array
            (
                [name-1] => Array
                    (
                        [id] => 436
                        [value] => Array
                            (
                                [first-name] => Anthony
                                [last-name] => Brooks
                            )
    
                    )
    ...

    I tried different tricks but sadly without success. First and last name went blank. To give you an example, this code snippet does not work:

    array(
    					'name' => 'name-1',
    					'value' => array(
    						'first-name' => 'new first name',
    						'last-name' => 'new last name'
    					)
    				)
    

    I also tried things like json_encode() and different names for keys (for example name-1-first-name). I’m running out of ideas. Could you help me out please?

    Thanks a lot!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @polistus

    I hope you are doing good today.

    I pinged our SLS team to review your query. Thank you for your patience while we look into this further.

    Kind Regards,
    Kris

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi again @polistus

    You will need to serialize the data as in this example snippet.
    Before testing, Form ID and Entry ID should be replaced with yours:

    $form_id = 2910;  // Please replace
    $entry_id = 5313; // Please replace
    $entry_meta= array(
    	array(
    		'name' => 'name-1',
    		'value' => maybe_serialize( array( 'first-name' => 'test first', 'last-name' => 'test last' ) )
    	)
    );
    
    Forminator_API::update_form_entry( $form_id, $entry_id, $entry_meta );

    Kind Regards,
    Kris

    Thread Starter polistus

    (@polistus)

    Hi Kris @wpmudevsupport13

    Including maybe_serialize() was the key! I can confirm that now it works as expected.

    Thank you very much. Please send my regards to your SLS team. You have been very helpful in solving this mystery for me.

    Have a nice day!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Updating First Name and Last Name Field Entries via API’ is closed to new replies.