Here’s the scenario: I have a contact form with few checkboxes:
<input type="text" name="cola[]" value="coke" />
<input type="text" name="cola[]" value="pepsi" />
<input type="text" name="cola[]" value="rc" />
Using jQuery’s serialize, I have the data string sent to my mailer.php like so:
$.ajax({
type: "POST",
url: "http://mydomain.com/mailer",
data: dataString,
success: function() {//some function}
});
Notice that I have had to omit the .php extension from the URL, due to a htaccess rewrite rule. If all 3 checkboxes are checked, the data string looks like: &cola=coke&cola=pepsi&cola=rc. I verified this using console.log.
mailer.php looks like this:
$cola = $_POST["cola"];
// other code
$message = "<p>" . $cola . "</p>";
// code to mail it out
However, upon successful mailing, the email body text just says “Array”, instead of “cola, pepsi, rc”.
I have a feeling it may be something to do with my rewrite conditions in my htaccess, which looks like this:
RewriteEngine On
# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://example.com/folder/$1 [R=301,L]
# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://example.com/folder/$1 [R=301,L]
# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]
My rewrite conditions are to remove any trailing / from the URL and wipe out the .php file extensions so that urls look like: domain.com/pretty
Can anybody help me diagnose why I’m getting the message “Array” instead of the array contents? Thank you!
It’s not your .htaccess the problem. In fact, $_POST[‘cola’] is an Array like this :
You need to loop through the Array and get your informations.
Hope this help.