Skip Navigation

[Resolved] The supplied code fails, Field “Title” is required..

This thread is resolved. Here is a description of the problem and solution.

Problem:

Create dynamic post title from custom fields.

Solution:

An example of how to achieve this can be seen below.

function gg_fill_full_name( $post_id, $form_data ){
	if ( $form_data['id'] == 126) {
		$firstname = get_post_meta( $post_id, 'wpcf-first-name', true );
		$middlename = get_post_meta( $post_id, 'wpcf-middle-name', true );
		$lastname = get_post_meta( $post_id, 'wpcf-last-name', true );
		$suffix = get_post_meta( $post_id, 'wpcf-name-suffix', true );
 	    
		if ($suffix == "None") {
			$suffix = '';
		}              
 
        $result = $lastname . $suffix . ", " . $firstname . " " . $middlename;
		
		
		
//		$result = $lastname . " " . $suffix . ", " . $firstname . " " . $middlename;

		if ( !empty($result) ) {
   			$my_post = array(
  				'ID' => $post_id,
   				'post_title' => $result,
			);

		// Update the post into the database
		wp_update_post( $my_post, $wp_error );
		}
	}
}
 
add_action('cred_submit_complete', 'gg_fill_full_name',10,2);
This support ticket is created 6 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 24 replies, has 4 voices.

Last updated by Gerard 6 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#1114541

Still the same 🙁

hidden link

Turned on Logging.. To screen and file..

Soo..

[24-Sep-2018 21:58:48 UTC] PHP Notice: Trying to get property of non-object in /nas/content/staging/bfsf/wp-content/plugins/types-access/includes/Helper.php on line 1604
[24-Sep-2018 21:59:05 UTC] PHP Notice: Trying to get property of non-object in /nas/content/staging/bfsf/wp-content/themes/bb-theme-child/functions.php on line 73

Line 73 of functions.php is :

if ( 'application' == $post->post_type ) {

#1115092

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gerard,

I see the issue. Its atually a problem with how the post type is being retrieved from the array.

function gg_fill_full_name( $post_id, $form_data ){
if ($form_data['post_type'] == 'application'  ) {
$firstname = get_post_meta( $post_id, 'wpcf-first-name', true );
$middlename = get_post_meta( $post_id, 'wpcf-middle-name', true );
$lastname = get_post_meta( $post_id, 'wpcf-last-name', true );
$suffix = get_post_meta( $post_id, 'wpcf-name-suffix', true );
 
$result = $lastname . " " . $suffix . ", " . $firstname . " " . $middlename;
if ( !empty($result) ) {
   $my_post = array(
  'ID' => $post_id,
   'post_title' => $result,
);
// Update the post into the database
wp_update_post( $my_post, $wp_error );
}
}
}

add_action('cred_save_data', 'gg_fill_full_name',10,2);

Please try the above.

Thanks,
Shane

#1115127

Hi,

Good try, but now it fails on creating the form. Seems to be having an issue with the file upload.. hidden link

There was a file missing message when I hovered over the file area earlier.

#1115128

BUT, the forms did upload and the files too.. Same title problem as before.

hidden link

So why that message?

#1115211

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gerard,

Would you mind allowing me to have admin access to the site so that i can take a further look at this ?

The private fields have been enabled.

Also please let me know the page that the form is on so that I can test it as well.

Thanks,
Shane

#1115213

OOps I forgot the link to the forms page. You'll see though, it's simple to find 😉

#1115721

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gerard,

It seems that the hook is causing the form not to fully submit when using AJAX.

I disabled the AJAX submission and now the form and custom hook should be working fine.

Please let me know if this helps.

Thanks,
Shane

#1115767

YES!!!

Why were there no errors or indications though? 🙁

But it's ok, AJAX is not required in this case..

Thanks!

#1115843

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Gerard,

I'm sure there was an error being thrown somewhere for it, but i'm not sure how to debug for the error.

So i'm not able to say what the error is but it is a known issue on our side.

Thanks,
Shane

#1115865

My issue is resolved now. Thank you!

Shame about the AJAX bug, but it'll have to do.

Is there a thread or forum we can follow somewhere about these bugs to stay on top of things and avoid week long troubleshooting when possible?

Thanks