Skip Navigation

[Resolved] Need to retrieve date and parent info inside a snippet

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

Problem: I am trying to use the Forms API, but I'm having trouble getting the value of a custom field and the selected post parent.

Solution: Use the 'wpcf-' prefix to access the value of a Types custom field in the Form, and use the parent field name to access the ID of the parent post.

$date_debut = $_POST['wpcf-date-debut-stage'];
$lieu = $_POST['@salle-product.parent'];
This support ticket is created 5 years, 7 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.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1270535

Pat

Hello,

I have a Cred form with the following elements :

    	<div class="form-group">
		<label>Date début stage</label>
		[cred_field field="date-debut-stage" force_type="field" class="form-control" output="bootstrap"]
	</div>

	<div class="form-group">
		<label>Lieu du stage</label>
      [cred_field field='@salle-product.parent' class='form-control' output='bootstrap' select_text='Choix de la salle' value='']
	</div>

'date-debut-stage' is a date field
'salle" is a textfield

I'm trying to setup a snippet with a cred_save_data to rewrite the post title after submission.

The salle-product is a types relationship (a salle could have several products)
I need to use the date format 'd,m,Y' in the title for the date and the title of the salle.

I have tried this :

$date_debut = $_POST['date-debut-stage'];
$datedeb = date('d,m,Y',$date_debut);
$lieu = toolset_get_related_post( $post_id, array( 'salle', 'product' ) );

but this is not working. Can you indicate how I could get the need info?

Thanks
Pat

#1270773

Hi, here are a couple of things to check.

1. Types fields have a wpcf- prefix, so you should update this line:

$date_debut = $_POST['wpcf-date-debut-stage'];

2. The form contains the parent post select field, so there's no need to use the API to get the parent post's ID. You can find the post ID in the $_POST object like this:

//$lieu = toolset_get_related_post( $post_id, array( 'salle', 'product' ) );
$lieu = $_POST['@salle-product.parent'];

I think the date formatting part looks okay. Try these two updates and let me know if the problem is not resolved.

#1270823

Pat

Hi Christian,

Many thanks. All is working fine with this.
I'm currently moving to your relationship feature and I need to continue to learn on it !!
Regards
Pat