0

We are using the Aheadworks Helpdesk Module and are trying to create a second form to capture specific information and use the form to create a ticket where all of the form content gets posted to the "content" section of Helpdesk.

The problem is, if I use the name="content", what gets posted into the "content" section is simply "Array"

The form code is quite simple:

<form id="helpdesk-ticket-form" action="../helpdeskultimate/customer/new/" method="post" enctype="multipart/form-data"><input name="title" value="WHOLESALE SETUP REQUEST" type="hidden">
<div><label for="title_field">Name<span class="required">*</span></label><br> <input id="title" class="input-text required-entry" style="width: 250px;" name="" value="" type="text"></div>
<div>&nbsp;</div>
<div><label for="title_field">Company Name<span class="required">*</span></label>    <br><input id="content_field" class="input-text " title="Company" name="content" value="" type="text"></div>
<input name="department_id" value="2" type="hidden">
<div>&nbsp;</div>
<div><label for="content_field">Message<span class="required">*</span></label><br>     <textarea id="content_field" class="required-entry" style="width: 450px;" name="content" rows="10" cols="53"></textarea></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><label for="filename">Attach Reseller Permit (2Mb limit)</label><br> <input id="filename" class="input-file" style="width: 450px;" name="filename" type="file"></div>
<div class="button-set">&nbsp;</div>
<div class="button-set"><span><span><br></span></span></div>
<div class="button-set"><button class="button right form-button" type="submit"><span>  <span>Submit ticket</span></span> </button></div>
</form>

I have tried using name="content[]" but it also returned "Array"

The module looks to be using this post method:

public function newAction()
{
    if (!$this->_getCustomerSession()->getCustomerId()) {
        $this->_getCustomerSession()->authenticate($this);
        return;
    }
    $session = Mage::getSingleton('core/session');
    $customer = $this->_getCustomerSession()->getCustomer();

    $Proto = Mage::getModel('helpdeskultimate/proto');
    $postData = $this->getRequest()->getPost();

    if (isset($postData['department_id'])) {
        $Proto->setDepartmentId($postData['department_id']);
    }
    try {

        $Proto
                ->setSubject(@$postData['title'])
                ->setContent(@$postData['content'])
                ->setPriority(@$postData['priority'])
                ->setStoreId(Mage::app()->getStore()->getId())
                ->setFrom(Mage::getSingleton('customer/customer')->getId())
                ->setSource('web');

The insert into the message field seems to come from here:

/* Insert */
    try {
        $message->setContent(trim($data['content']));
        $validateResult = $message->validate();

The full controller file can be downloaded from http://www.gingabox.com/CustomerController.zip

I am not sure how to actually use a foreach statement with the @$postData['content'], or if there is a better solution.

I would happily ask AheadWorks, but have been told by them that they are not accepting customization inquiries at this time (too busy)...

Any help would be greatly appreciated!

9
  • $this->getRequest()->getPost(); retrieves all of the post data in a single array, does $this->getRequest()->getPost('content'); also return just the type? Commented Aug 27, 2013 at 2:09
  • Thank you Joe. I am not familiar with the structure, could you point me in the right direction? Would that replace the @postdata['content'] line? Commented Aug 27, 2013 at 4:20
  • Ahh, sorry I think I understand... I changed $postData = $this->getRequest()->getPost(); to $postData = $this->getRequest()->getPost('content'); This however causes the ticket to not post any of the input values and returns an error. Commented Aug 27, 2013 at 6:37
  • I was unable to find much documentation about the inner workings of helpdesk ultimate, but this question regarding magneto suggests getParam, so maybe try $this->getRequest()->getParam('content'). Failing all else, have you tried $_POST['content']? Commented Aug 29, 2013 at 1:51
  • Thank you for your help and taking the time to look for a solution. I tried both of the above. $this->getRequest()->getParam('content') returns an error (missing input data error) $_POST['content'] posts "Array" I also tried adding $_POST = $this->getRequest()->getPost('content'); to the compliment $_POST['content'] and it also gets a missing input error. Commented Aug 29, 2013 at 6:08

2 Answers 2

1
+50

The word "Array" is what you get when you convert a PHP array into a string; since array values can contain anything, PHP doesn't bother trying to figure out how to convert an array and just returns the string "Array". This is exactly what happens in the line:

// The trim() function casts $data as a string => string(5) "Array"
$message->setContent(trim($data['content']));

There are functions that do return a string representation of array contents, such as print_r(). This will spit out the array in a multiline string, so incorporating that in your code would be:

$message->setContent(print_r($data['content'], TRUE));

If you wanted the contents of the array as a single-line string you should probably use a foreach() statement like you mentioned in your question. Here's a quick example:

$contentString = 'Second Form values:' . PHP_EOL;
foreach($data['content'] as $key => $value) {
    $contentString .= PHP_EOL . '    ' . $key . ': ' . $value;
}

Then you would be able to use $contentString as the message instead of accessing the $data array value directly. I don't know what the validate() method is doing in your example, but it is definitely a good idea to ensure that you are properly escaping the values within this second form before you use them as the body of an email.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for the suggestions. I have tried the print_r() example and still get "Array", but not sure where I the foreach() example would be placed. Your help is very much appreciated!
The four lines in my foreach() example should be placed inside your second try block, just above the line where $message->setContent happens. Then instead of setting the message with $data['content'] you would use $contentString in its place.
Thank you for the information! Unfortunately it still returns "Array". I set $message->setContent(print_r($contentString, TRUE)); Not quite sure where to go from here. But, thank you again for your help.
If you are using the foreach() construct then you don't need the print_r() call in your code. Just use $message->setContent($contentString); and you should be fine.
0

If you can change the form definition in HTML then maybe you will be able to receive an array as content, please have a look at the following example:

<form id="helpdesk-ticket-form" action="tescik.php" method="post" enctype="multipart/form-data"><input name="title" value="WHOLESALE SETUP REQUEST" type="hidden">
<div><label for="title_field">Name<span class="required">*</span></label><br> <input id="title" class="input-text required-entry" style="width: 250px;" name="content[name]" value="" type="text"></div>
<div>&nbsp;</div>
<div><label for="title_field">Company Name<span class="required">*</span></label>    <br><input id="content_field" class="input-text " title="Company" name="content[company]" value="" type="text"></div>
<input name="department_id" value="2" type="hidden">
<div>&nbsp;</div>
<div><label for="content_field">Message<span class="required">*</span></label><br>     <textarea id="content_field" class="required-entry" style="width: 450px;" name="content[message]" rows="10" cols="53"></textarea></div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><label for="filename">Attach Reseller Permit (2Mb limit)</label><br> <input id="filename" class="input-file" style="width: 450px;" name="filename" type="file"></div>
<div class="button-set">&nbsp;</div>
<div class="button-set"><span><span><br></span></span></div>
<div class="button-set"><button class="button right form-button" type="submit"><span>  <span>Submit ticket</span></span> </button></div>
</form>

Please note the changed form names like content[message], content[company] etc. This should resolve to an Array of values.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.