We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Allow users to upload file

How Do I?

calero's avatar
calero
2 posts
3 years ago
calero's avatar calero

Im new to EE and I have a working form that I can submit it to the entries, but only text, once I try to submit files I get this error:

The form you submitted contained the following errors

Flower Image: Invalid Selection flower_image: Invalid Selection

you can test it here: iptlaws.com

here is the code of the form:

{exp:channel:form channel="flowers" }            
            <div class="mb-3">
                <input class="form-control" type="text" id="flower_name" name="title" placeholder="Flower Name">
            </div>

            <textarea class="form-control" name="flower_description" id="flower_description" placeholder="Flower Description"></textarea>
            <!--{field:flower_image}-->
            

    <input type="file" name="flower_image" />
    <input type="hidden" name="images" value="1" />
            
             <!--<input  type="file" name="flower_image" field="flower_image"/> -->
     

            <button type="submit" name="submit" class="btn btn-primary" value="upload">upload</button>
   {/exp:channel:form}
       
Andy McCormick's avatar
Andy McCormick
322 posts
3 years ago
Andy McCormick's avatar Andy McCormick

I think we need to update the docs to explain this a little clearer. This issue with your code above is the file upload directory.

The name property of that hidden field should actually be flower_image_directory and the value is the ID of the file upload directory where the files are going to be uploaded.

For examples, if the name of the my field is flower_image and I’m uploading to a File Upload directory called Flowers with an ID of 5, then my hidden input field would be <input type="hidden" name="flower_image_directory" value="5" /> .

If you don’t know the ID of the upload directory you are trying to use, then you can go to that directory in the Control Panel and the ID is the last segment in the URL. So for my example above, the URL for that directory in the CP would be https://ee60testing.test/admin.php?/cp/files/directory/5 . Where 5 is the last segment of the control panel URL and the ID of the directory.

       
calero's avatar
calero
2 posts
3 years ago
calero's avatar calero

Thank you so much, I updated the names and values now the form is working no errors but still the images is not getting upload, so frustrated here is the changes.

{exp:channel:form channel="flowers" }
<div class=”mb-3”> <input class=”form-control” type=”text” id=”flower_name” name=”title” placeholder=”Flower Name”> </div>

        <textarea class="form-control" name="flower_description" id="flower_description" placeholder="Flower Description"></textarea>

         <input  type="file" name="flower_image_directory" /> 

        <input type="hidden" name="flower_image_directory" value="5" /> 

        <button type="submit" name="submit" class="btn btn-primary" value="upload">upload</button>
    {/exp:channel:form}
       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.