I'm trying to get data submitted from a form using craft()->request->getPost(), but I'm not sure what to do when the form name is an array element.
For example, I have a form with:
<label for="notes">Notes</label>
<textarea rows="6" id="notes" name="fields[notes]"></textarea>
and want to use:
craft()->request->getPost('fields[notes]');
but when I do this I don't get any data from the form, and I'm not sure what to put in getPost() to let it know its an array.
It will work fine if I change the name to "notes" and use getPost('notes'), but I'd like to be able to get it working with the array.
\CUploadedFile::getInstanceByName('fields.file')work the same way? This part is still not working for me and I'm not sure if it is supposed to work the same way or if there is some other error in my code. – user418 Jun 27 '14 at 20:15getInstanceByName('fields[emp_resume]');which is what wouldn't work before. I am confused why it works here but not in the other case, and how I'm supposed to remember which way will work? – user418 Jun 27 '14 at 20:35$_POST,$_FILES) but the abstraction to find nested keys is implemented differently in for each purpose. For example, when you docraft()->request->getPost('fields.notes)you're saying "Craft, look at the$_POSTarray and find the passed in (dot notated) string" so Craft will check if there is afileskey and then check if anoteskey exist within thefileskeys. When you use\CUploadedFile::getInstanceByName('fields[file])Yii will look for what you want in the$_FILESarray not the$_POST` array. – Selvin Ortiz Jun 27 '14 at 21:14fields.notes) and bracket notation (fields[file) are both syntactic sugar added on top of arrays. You could easily grab the first key from both and then look for the nested key within them in vanilla PHP or use theisset()technique. – Selvin Ortiz Jun 27 '14 at 21:20