Skip Navigation

[Resuelto] The supplied code fails, Field «Title» is required..

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 6 años, 2 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 24 respuestas, tiene 4 mensajes.

Última actualización por Gerard hace 6 años, 2 meses.

Asistido por: Shane.

Autor
Mensajes
#1114541

Still the same 🙁

enlace oculto

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

Idiomas: Inglés (English )

Zona horaria: 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.. enlace oculto

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.

enlace oculto

So why that message?

#1115211

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: 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