Jump to content

\IPS\Helpers\Form\Upload field returns Error code: -200


Cory_DSL
 Share

Recommended Posts

I have a form in the admin side, with an Upload field. I can't debug or pinpoint where the error is. Same issue with attaching an image in an Editor field.

Error: Sorry, an unknown server error occurred when uploading this file. (Error code: -200)

$form = new \IPS\Helpers\Form('form');
$form->add(new \IPS\Helpers\Form\Upload(
	'acp_points_earnpoints__field_photo', // name
	$earnPoint->photo ? \IPS\File::get('dslambassador_earnPoints', $earnPoint->photo) : null, // defaultValue
	false, // required
	array(
		'image' => array(
			'maxWidth' => 200,
			'maxHeight' => 200,
		),
		'allowedFileTypes' => array('jpeg', 'jpg', 'png', 'gif'),
		'allowStockPhotos' => true,
		'storageExtension' => 'dslambassador_EarnPoints',
	), // options
	null, // customValidationCode
	null, // prefix
	null, // suffix
	'acp_points_earnpoints__field_photo', // id
));

if ($values = $form->values()) {
	$earnPoint = new \IPS\dslambassador\Models\EarnPoint;
	$earnPoint->name = $values['acp_points_earnpoints__field_name'];
	$earnPoint->photo = $values['acp_points_earnpoints__field_photo'] ? (string) $values['acp_points_earnpoints__field_photo'] : null;
	$earnPoint->save();
}

image.thumb.png.b5947985325167778fdfac3c5a8b74e2.png

Link to comment
Share on other sites

Turns out the module controller class doesn't have:

public static $csrfProtected = true;

when created via Developer Center, so I added it.

The file system/Dispatcher/Admin.php checks if the class is csrfProtected, if not then it will do a session check:

/* Unless there is a flag telling us we have specifically added CSRF checks, assume any AdminCP action which contains more than app/module/controller/id (i.e. anything with "do") requires CSRF-protection */
if ( !isset( $this->classname::$csrfProtected ) and array_diff( array_keys( \IPS\Request::i()->url()->queryString ), array( 'app', 'module', 'controller', 'id' ) ) )
{
	\IPS\Session::i()->csrfCheck();
}

Which then causes the Error -200.

For the record, the error that I'm experiencing is from the admin's side. I haven't tried the upload feature from the front side, so I'm not sure if this solution is applicable to other Error -200 issues. Hope this helps if others are experiencing it.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...