Validate attachments for file size? Does anyone know if it's possible to validate the size of an attachment for Sprout Forms file upload? I'd like to limit attachments to a maximum file size.
I'm not sure if that's possible since I never used Sproud Forms but you can easily create a custom field type with the additional validation rule.


Create a Plugin you can use Pluginfactory.io for that and install it
Create a new Field 
Just extend the basic AssetsFieldType

class myNewAssetField extends AssetsFieldType{

}

Take a look at the default validation rules for BaseElementFieldType

public function validate($value)
{
    $errors = array();

    if ($this-&gt;allowLimit &amp;&amp; ($limit = $this-&gt;getSettings()-&gt;limit) &amp;&amp; is_array($value) &amp;&amp; count($value) &gt; $limit)
    {
        if ($limit == 1)
        {
            $errors[] = Craft::t('There can’t be more than one selection.');
        }
        else
        {
            $errors[] = Craft::t('There can’t be more than {limit} selections.', array('limit' =&gt; $limit));
        }
    }

    if ($errors)
    {
        return $errors;
    }
    else
    {
        return true;
    }
}

Copy the function above in your new class and include something like this somewhere

foreach ($value as $assetId){
    $asset = craft()-&gt;assets-&gt;getFileById($assetId);
    if($asset-&gt;size &gt;= 10){ // insert your size here
        $errors[] = Craft::t('Your file is too large');
    }
}



It took me about 5 minutes to create this new field type to allow the validation of file sizes

If you want to make it look pretty and create a setting to dynamically set the individual max file size for each field you can include the function getSettingsHtml in your new class and change add your new value (for example maxSize) you can then grab the new size with $this-&gt;getSettings()-&gt;maxSize