Forums

File Upload Value Reset after Record Edit

ozneilau 11 Aug, 2011
Hi,

I am using ChronoForms v3.2 and ChronoConnectivity v2_RC3 to maintain a tour database on Joomla 1.5.

I have some file upload fields defined in a ChronoForm so that I can upload some photos.

This works well when a photo is added but when the record is subsequently edited using ChronoConnectivity, the file upload fields are reset back to null.

I have similar websites working without this problem but they were developed using ChronoForms v3.1_RC5.2.

Note that I have already applied the "File Upload Fix" as per http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&p=60769#p60769

The website is at: http://cewa2.webilicious.com.au and I can PM some administrator credentials if required.

Can you help?

Thanks,

Neil
GreyHead 11 Aug, 2011
Hi Neil,

First off, I simply don't use the ChronoConnectivity edit_record links but use direct URLs to the form instead. I find this gives me much more reliable control.

I think we had the blank filename problem in another thread recently and, if I remember correctly, the answer was to load check the form results and unset the file input if the result was empty. This saves the 'blank' result over-writing the existing database entry.

Bob
ozneilau 20 Aug, 2011
Hi Bob,

OK, your suggested fix worked for menchee according to this post: http://chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=12&t=21682 but didn't work for me.

I eventually worked out something that does work for me though:

<?php
  $photo1 = JRequest::getString('photo1', '', 'post');
  if ($photo1 == "NOFILE") {
    unset($_POST['photo1']);
  }
?>

I'm not sure I understand why but at least it's working now!

Thanks for getting me on the right track.

Neil.
GreyHead 20 Aug, 2011
Hi Neil,

Interesting - I wonder where the NOFILE value comes from? If that's browser specific it might be worth setting NOFILE as the default value in the JRequest line so that empty entries get caught as well.
$photo1 = JRequest::getString('photo1', 'NOFILE', 'post');

Bob
ozneilau 21 Aug, 2011
Hi Bob,

Yes it is interesting and browser specific it would seem. Tests show the following results:

Problem present but able to be fixed with the above code in the following browsers:

[list]FireFox v6.0 on Ubuntu Linux 11.04 (Natty)
Internet Explorer 7 on Windows XP
Internet Explorer 8 on Windows XP
Internet Explorer 9 on Windows 7
Safari 5.0.3 on Windows XP
Safari 5.0.5 on Snow Leopard 10.6.7[/list]
Problem was not present in the following browsers:

[list]Chrome v13 on Ubuntu Linux 11.04 (Natty)
Opera v11.5 on Ubuntu Linux 11.04 (Natty)[/list]
I have modified the above code for multiple file upload fields and include it here in case it may be useful for anyone else:

<?php
  for ($n=1; $n<=5; $n++) {
    $image = "photo" . $n;
    $photo = JRequest::getString("$image", '', 'post');
    if ($photo == "NOFILE") {
      unset($_POST["$image"]);
    }
  }
?>

Thanks for your help with this.

Neil.
kuti 22 Sep, 2011
Sorry Neil and everyone for bring back this topic because I just met this problem as well so I thought maybe I should post here rather create a new thread.

I use chronoform v3.2 and also patch "File upload fix".

I tried every solution and still having this problem.

Please see my code below:

Neil suggested:
<?php
$file_1 = JRequest::getString('file_1', '', 'post');
if ( $file_1 == "NOFILE" ) {
  unset($_POST['file_1']);
}
?>



Bob added
<?php
$file_1 = JRequest::getString('file_1', 'NOFILE', 'post');
if ( $file_1 == "NOFILE" ) {
  unset($_POST['file_1']);
}
?>


Bob's method
<?php
$file_1 = JRequest::getString('file_1', '', 'post');
if ( !$file_1 ) {
  unset($_POST['file_1']);
}
?>


Please can someone assist me !!!

Many thanks
ozneil 22 Sep, 2011
Hi kuti,

What version of ChronoForms are you using?

Have you applied the "File Upload Fix" as per viewtopic.php?p=60769#p60769 ?

Neil
kuti 22 Sep, 2011
Hi Neil,

Yes, I already applied that file upload fix.

I use: Chronoform V3.2.0 and ChronoConnectivity V2_RC3

Thank you.
ozneil 22 Sep, 2011
Hu kuti,

When I was trying to find the fault on my client's website, I added the unset code unconditionally and then edited one of the records with an attachment to see if the problem was fixed (it was).

Then I went about finding what was the relevant condition to test for so that the unset code wasn't executed for new attachments.

I hope this helps - it's a bit tricky to solve without being able to access the website.

Neil
kuti 22 Sep, 2011
Hi Neil,

Thank you very much for your guide.

Though I still confused about it but I will try to do something like your guide.

Many thanks,

kuti
ozneilau 23 Sep, 2011
Hi Kuti,

I thought about a couple of other ways that might help you track down the problem.

1. Is the problem browser specific? For example, I found the problem with Firefox but Chrome worked OK.

2. I usually include some PHP in my form to show if attachments have been uploaded and this may shed some light on the issue for you. When no file has been uploaded, the form shows "NOFILE".

Here is the code. There is more code for other attachments but you will get the idea.


<?php
  $tourid = JRequest::getVar('cids');
  $db =& JFactory::getDBO();
  $db->setQuery("SELECT * FROM #__chronoforms_Tour WHERE cf_id = $tourid;");
  $d = $db->loadObject();
  if (isset($d)) {
    $photo1 = $d->photo1;
  }
?>
<div class="form_item">
  <div class="form_element cf_fileupload">
    <label class="cf_label" style="width: 20px;">1:</label>
    <input class="cf_fileinput cf_inputbox" title="needs to be jpg or png file up to 1MB" size="25" id="file_69" name="photo1" type="file" />
    <?php if (isset($photo1)) echo "<div class='cewaphoto'>$photo1</div>"; ?>
  </div>
  <div class="cfclear"> </div>
</div>
etc.

Neil.
kuti 23 Sep, 2011
Hi Neil,

You are very kind.

Here is the morning so I just see your code, I will try it and let you know.

Many thanks,

kuti
kuti 23 Sep, 2011
Hi Neil,

Following your guide when I opened to edit a record, it showed the file name and its path next to the file upload field.

After I clicked on Submit button to save the record, the browser redirect the page back to chronoconnectivity record list on front-end website, I checked the upload field and now it showed "NOFILE".

Although I tried your code and Bob's way many time, it still unsuccessful to correct this bug.

May I ask about your form, it is one page or multipage form? And I don't know if this will affect at all.

Many thanks,

kuti
GreyHead 23 Sep, 2011
Hi kuti,

By all means email or PM me the site URL and a SuperAdmin login and I'll take a quick look.

Bob
This topic is locked and no more replies can be posted.