Skip Navigation

[Resolved] Displaying parent field as default value

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

Problem:
Display default value for date field in CRED form.
Solution:
Solution here:
https://toolset.com/forums/topic/displaying-parent-field-as-default-value/#post-614192
Relevant Documentation:

This support ticket is created 6 years, 9 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.

Our next available supporter will start replying to tickets in about 1.87 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by gavinS-2 6 years, 9 months ago.

Assisted by: Noman.

Author
Posts
#614088

Tell us what you are trying to do?

I have a single post page for a parent field (request). On the page I have a CRED form for submitting fields for a child type (request-lines). I am trying to use the request field 'start-date' as a default value for the request-line field 'line-start-date'. (Ie. I want the field for the parent start-date to display on the form as the default value for line-start-date.)

Is there any documentation that you are following?

I have been trying to follow this: https://toolset.com/forums/topic/cred-form-dynamic-default-value-based-on-post-custom-field/ (#56273) where it says I should try and do this:

[cred-field field="benchmark" post="wod-logs" value='[types field="xxxx" id="$yyyy"]']

On my form I have the following:

<div class="form-group">
		<label>Line Start Date</label>
		[cred_field field='line-start-date' post='request-line' value='[types field="start-date" id="$request"]' urlparam='' class='form-control' output='bootstrap']
	</div>

But even though there is a value for start-date, the line-start-date is showing as a blank.

What is the link to your site?

hidden link

#614192

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Gavin,

Thank you for contacting Toolset support. Date filed takes value in unix timestamp. You can fix this issue by adding following code in your theme’s or child theme’s functions.php file

function convert_date_timestamp_func($atts) {
	$a = (shortcode_atts(array(
	    'date_string' => '',
   ), $atts));
   $date_string = $a['date_string'];
   $date_timestamp = strtotime($date_string);
   return $date_timestamp;
}
add_shortcode('convert_date_timestamp', 'convert_date_timestamp_func');

And then use following field in CRED form.

<div class="form-group">
        <label>Line Start Date</label>
[cred_field field='line-start-date' post='request-line' value='[convert_date_timestamp date_string="[types field="start-date" id="$request"][/types]"]' urlparam='' class='form-control' output='bootstrap']
</div>

I hope it helps.

Thank you

#614201

It works!

Thank you sir