HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


form_input_upload question....

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#91296 (In Topic #18380)
Avatar

Community saint

 For the function 'form_input_upload', is there a way to indicated that an image was already selected?

Meaning, you add an entry, you select an image file and fill in the fields, it saves it.   But if you edit that entry, it doesn't put anything in the 'image' input…  and I have that set to required…  so you can't resave it unless you select that file again.

Whereas with form_input_line you can pass it a variable with what it is set to, and it fills it in…  _upload seems not to work that way.

Paul
Back to the top
 
Posted
Rating:
#91299
Avatar

Thx for putting in own topic :). Now I can answer  :lol:

It's a good question, and I'm clarifying in the API documentation because it's not at all clear currently.

There is special support for editing non-required upload fields, allowing you to delete the existing file when editing. This would involve filling in the $default parameter.

There is no special support for editing required upload fields, so you need to pass in different parameters when editing. For this scenario you need to always leave the $default parameter blank or NULL.

Usually ocPortal has two fields: an upload field, and a URL field. That's how we handle it – after uploading, you go to edit and the URL field is filled in. E.g. cms_iotds.php does this.

But it's optional to go to those lengths, you can do something like…

Code

$pretty_name=...;
$description=...;
$name='file';
$required=true;
if ($existing_upload!='')
{
   $required=false;
   $pretty_name=do_lang_tempcode('REPLACEMENT_FIELD',$pretty_name);
}
$upload_field=form_input_upload($pretty_name,$description,$name,$required);
And define the REPLACEMENT_FIELD language string somewhere:

Code

REPLACEMENT_FIELD=New {1} file

Then later when you read the upload in for an edit you'd need some logic like:

Code

$urls=get_url('','file','uploads/somewhere',0,OCP_UPLOAD_IMAGE);

$previous_upload_value=...;
if (($urls[0]!='')
{
   $new_upload_value=$urls[0]; // Get new value
   @unlink(get_custom_file_base().'/'.rawurldecode($previous_upload_value));
} else {
   $new_upload_value=$previous_upload_value;
}


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91342
Avatar

Community saint

Thanks, I'll read that more closely and fiddle with it tomorrow.

Paul
Back to the top
 
Posted
Rating:
#91356
Avatar

Community saint

Ok, perhaps my brain still isn't awake enough, but I'm looking at the code, and looking at the code I already have, and not getting it.

Perhaps I did not state the question clear enough, or perhaps I'm just too brain dead to see the answer.

The 'image' field I set as required, because, there is no point in having a reward of any type if you don't have an image.    So I add a new reward, that works.   It uploads the image file, and it is good.

But I want to go back in because I set the type wrong, or to change the description…    but it won't let me save because the  'image' field on the form is blank.  And that field is required.

I am trying to get it to know that the 'image' field exists, because it existed before, without having to select and upload the image file again.


Paul
Back to the top
 
Posted
Rating:
#91357
Avatar

so you need to pass in different parameters when editing

One of those being required must be set to false, as in the example:

Code

$required=true;
if ($existing_upload!='')
{
   $required=false;


Become a fan of ocPortal on Facebook or add me as a friend. Add me on on Twitter.
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about ocPortal whenever you see the opportunity.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying ocPortal on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
 
Posted
Rating:
#91358
Avatar

Community saint

I see what you are saying…   thanks.

Paul
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: