Skip Navigation

[Resolved] Preselect an intermediary post field value in a relationship edit form

This support ticket is created 4 years, 1 month 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

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

Author
Posts
#1564615

Tell us what you are trying to do?

I have a relationship form which I use to edit a relationship. In this form I try to preselect a value in an intermediary custom field, that is different from the value, that was previously saved, when the relationship was created.

Example:
When the relationship is created, the intermediary custom firld should save 'no'
In the edit form 'request' should be preselected in this intermediary custom field.

The code of my relationship form:


[cred-relationship-form-container]
	[cred-form-feedback field='feedback' name='feedback']
	<div class="form-group">
		<label>Benutzerprofile</label>
		[cred-relationship-role role='parent' orderby='title' author='$current' class='cuteberry-relationshipformfield']
	</div>
	<div class="form-group">
		<label>Reitanlagen</label>
		[cred-relationship-role role='child']
	</div>

<!-- I try to change this field -->

	<div class="form-group">
		<label>Organisatorrechte für das Anwesenheitsjournal</label>
		[cred-relationship-field name='organisatorrechte-fur-das-anwesenheitsjournal']
	</div>



	<div class="form-group">
		<label>Warum sollte ich Organisatorenrechte für das Anwesenheitsjournal haben?</label>
		[cred-relationship-field name='warum-sollte-ich-organisatorenrechte-fur-das-anwesenheitsjournal-haben']
	</div>
	[cred-form-cancel field='cancel' name='cancel']
	[cred-form-submit field='submit' name='submit']
[/cred-relationship-form-container]

This is the php which is in the documentation:


<?php
toolset_snippet_security_check() or die( 'Direct access is not allowed' );
  
/**
 * Reset parent post ID on post edit form
 */
function ts_override_parent( $form_data ){
     
    $form_id = '5888';
     
    if ( $form_data['id'] == $form_id ){
  
        // reset parent
        $_POST['@buchungssystem-selbstportrat_parent'] = '4668';
        $_POST['@selbstportrat-element_parent'] = '4702';
    }
}
add_action( 'cred_before_save_data', 'ts_override_parent' );

Is there any documentation that you are following?
https://toolset.com/forums/topic/one-to-many-relationship-edit-post-form/page/2/#post-1564431
Nigel helped me to do something similar with a post form, where I changed the parents. I tried very hard to figure out, how I can do the same with the relationship form, but I does not work somehow

Is there a similar example that we can see?
Comepare answer above

What is the link to your site?
hidden link

#1565081

Waqar
Supporter

Languages: English (English )

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

Hi,

Thank you for contacting us and I'd be happy to assist.

To suggest the best way forward, I'll need to see exactly how this relationship form and the intermediary custom field is set up.

Can you please share temporary admin login details, along with the link to a page with this form?

This way I'll be able to perform some tests with a similar form on my test website and suggest accordingly.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1565271

Waqar
Supporter

Languages: English (English )

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

Hi Lara,

Thank you for sharing these details.

The admin access works, but that user seems to have limited capabilities.

Can you please update that user to have the "administrator" role, so that I can access all the sections.

regards,
Waqar

#1565303

Hi Waqar,
ups sorry. No it has administrator rights 🙂

Kind regards
Lara

#1565319

Now it has administrator rights 🙂. It should be NOW not NO. 😶😔, Sorry

#1565401

Waqar
Supporter

Languages: English (English )

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

Hi Lara,

Thank you for updating the user role and I can now access that form and the page.

If your goal is only to pre-select the "angefragt" option in that custom field ( screenshot: hidden link ), when the page with the form loads ( regardless of the previously saved value ), you can include the following script in the form's "JS editor" tab:
( screenshot: hidden link )


jQuery( document ).ready(function() {
    jQuery('select[name="wpcf[organisatorrechte-fur-das-anwesenheitsjournal]"]').val('angefragt');
});

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1565477

Wow, cool. What a simple solution. Thank you so much, Waqar. It's awesome.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.