Tell us what you are trying to do?
I have to customs fields in a CRED form. Field B ('wpcf-rask-bis-tag') should have the same value like field A ('wpcf-rask-von-tag'), if the field is empty, when the CRED form is submitted
add_action('cred_before_save_data', 'func_assign_field_value',10,1);
function func_assign_field_value($form_data)
{
// if a specific form
$forms = array( 5629 , 10440 , 10362 );
if (in_array($form_data['id'], $forms))
{
if (isset($_POST['wpcf-rask-bis-tag'])) {
$_POST['wpcf-rask-bis-tag'] = $_POST['wpcf-rask-von-tag'];
}
}
}
What is the problem?
Now Field B has always the value of Field A - no matter if it was empty previously or not ..
Is there any documentation that you are following?
Yes, there was a documentation, but I can't find it anymore.
Is there a similar example that we can see?
In the documenatation, that I lost
What is the link to your site?
https:// cuteberry.de
Hi,
Thank you for contacting us and I'd be happy to assist.
If your goal is to make "wpcf-rask-bis-tag" field use the same value as the "wpcf-rask-von-tag" field, only when "wpcf-rask-bis-tag" field's own value is empty, you can adjust your code to:
add_action('cred_before_save_data', 'func_assign_field_value',10,1);
function func_assign_field_value($form_data)
{
// if a specific form
$forms = array( 5629 , 10440 , 10362 );
if (in_array($form_data['id'], $forms))
{
// if value of wpcf-rask-bis-tag field is empty
if (empty($_POST['wpcf-rask-bis-tag'])) {
// make wpcf-rask-bis-tag field use the same value as the wpcf-rask-von-tag field
$_POST['wpcf-rask-bis-tag'] = $_POST['wpcf-rask-von-tag'];
}
}
}
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Thanks Waqar! Now it works perfectly.
Using empty instead of isset solved the problem 🙂
I try to re-open. I didn't test properly. Today a beta-tester pointed out that it still doesn't work.
The wpcf-rask-bis-tag is a datepicker field. Is it possible, that it is not empty by default? I mean, even before the user set a date?