I’m having a problem with using one of the atts array passed from a shortcode I’ve written. I want this function to get the email address passed by send_to in the atts array but it keep returning blank. The function then updates the form that’s included with a hidden field indicating where the form should be sent. Looking at the source HTML output it’s including everything bar the email address passed as send_to.
I’d really appreciate someone helping, or pointing out my glaring error.
The shortcode is [forms id=‘Question’ send_to=‘me@me.com’]
Ok, a few things.It is a good idea to have names and id’s the same… Email != email. Also can I see form-mail-handler.php? Nothing in your code sets the form values to PHP variables.
I take your point about names and ID’s. They were the same (honest), but I changed them after I started writing the code below, but before I put the array_change_key_case function in.
My only defence is that I’m new to php so I’m kind of winging it.
I don’t think that this will solve the problem. The else part of the code above is meant to default to the generic email address if there is no $to variable in the $_POST array. This file is only called when the form is submitted.
When I look at the source html code generated using the shortcode, if I use a default setting for send_to in the shortcode atts there will be the hidden “to” field with the value of the default email address I used.
For example, using the shortcode [forms id=‘question’ send_to=‘me@me.com’] this code:
Richard,
I cannot tell if you actually tried my suggestion or not. If I missed it, I am sorry, let me know, and relook at your code. However, it seems like you were just trying to show how I was wrong without even attempting it.
With the version above, if there is no $send_to variable set by the shortcode the form is sent to us@us.com. When I set one using the shortcode and submit the form the mail function doesn’t work, but I think that this is because the default value for the shortcode variable $send_to is an empty string.
I did try $hidden_to as well (I pasted the code into the function) but it doesn’t work becuase $hidden_to is a string that contains the hidden form field. So when I use the php mail function it would try to send the email to <input name=“to” type=“hidden” value=“” />.
I’ve just tried the double quotes as well but no joy.