Tell us what you are trying to do?
I have a CRED form with three select fields. If select field A has a certain value, select field C should change it's value through custom code. The custom code works fine. The only problem, that I am facing is, that I don't know, how I should apply the if condition with the CRED select field. The code:
add_action('cred_before_save_data', 'update_zeiteinteilung',10,1);
function update_zeiteinteilung($form_data)
{
// if a specific form
$forms = array( 12807 );
if (in_array($form_data['id'], $forms)) {
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] = 2) {
$von_zeit_30 = $_POST['wpcf-rask-von-uhrzeit'];
$bis_zeit_30 = $_POST['wpcf-rask-bis-uhrzeit'];
$new_von_zeit_15 = $von_zeit_30 * 2 - 1;
$new_bis_zeit_15 = $bis_zeit_30 * 2;
$_POST['wpcf-rask-von-uhrzeit-15-minuten'] = $new_von_zeit_15;
$_POST['wpcf-rask-bis-uhrzeit-15-minuten'] = $new_bis_zeit_15;
}
}
}
The code line with the problem ..
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] = 2) {
The custom field content of the "rask-von-uhrzeir-15-minuten" field can be 1, 2 or 3. Default is 1.
The custom code should only be executed, if the value is 2
Is there any documentation that you are following?
no
Is there a similar example that we can see?
no
What is the link to your site?
hidden link
Hello,
There is a problem in your custom PHP codes, this line:
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] = 2) {
Will always set var $_POST['wpcf-rask-von-uhrzeit-15-minuten'] value to 2, it does not check the value at all.
In your case, you can change that line as below:
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] == 2) {
More help:
hidden link
$a == $b Equal TRUE if $a is equal to $b after type juggling.
Many thanks for your explanation, Luo. I wasn't aware, that ..
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] = 2) {
... sets the value to 2. But it does make sense.
I already tried this ...
if ($_POST['wpcf-rask-von-uhrzeit-15-minuten'] == 2) {
... last night. It doesn't work. The code after that line, will not be executed. Do I need to include the data typ als well? Like in this example: $_POST['wpcf-rask-bis-tag']['datepicker'] ? I am a little bit lost ..
Kind regards
Lara
My issue is resolved now. Thank you!
After I uploaded the image, I realized, that I accidently used the wrong field. I am truely sorry.
With ...
if ($_POST['wpcf-rask-art-der-teilnehmerliste-tag']['radio'] == "2") {
... it works perfectly.