So I am using some code in my functions.php file to alter the subject of the email form when sent. I can get it to send just what is selected from the subject dropdown just fine and I can get it to include what is put in the “Other” field. But I haven’t been able to find a solid way to only target the “Other” option from the dropdown/select element so that what is entered into the “Other” text field is only added to the subject ONLY IF the user selects “Other” from the select element. Any ideas?
Here’s what I have currently…
// Changes the Enfold form subject
add_filter('avf_form_subject','avia_change_mail_subject', 10, 3);
function avia_change_mail_subject($subject, $new_post, $form_params){
$from_name = urldecode($new_post['1_1']);
$old_subject = urldecode($new_post['3_1']);
$subject = $old_subject .' - '. $from_name;
$other = urldecode($new_post['4_1']);
if ($other){
return $subject . ' - ' . $other;
}
else {
return $subject;
}
}
Hey Kahil,
Thank you for using Enfold.
Please provide a link to the page with the contact form so that we can inspect it.
Best regards,
Ismael
There isn’t an issue with the code or the form, I’m just asking if there was a way to disable/enable entry of a text field based on the option chosen in a select box.
Hi,
What if you check if the $other variable is not empty?
if ( $other != '' ) {
I’m not sure if that’s what you want but if we can see the contact form, maybe we’ll be able to understand it better.
Best regards,
Ismael
Well I don’t care if the other field is empty as it would be unless someone didn’t select “other” from the select box. I think it will involve some JavaScript.