CMS Made Simple Forums
https://forum.cmsmadesimple.org/

CGBetterForms- uploads with spaces
https://forum.cmsmadesimple.org/viewtopic.php?f=7&t=82281
Page 1 of 1

Author:  afrimax1 [ Wed Jun 10, 2020 3:51 pm ]
Post subject:  CGBetterForms- uploads with spaces

I installed CMSMS v2.2.11 and CGBetterForms v1.10.4 for a client website.

The form allows a visitor to fill in their information and upload a resume in PDF form to apply for listed jobs. The client gets and email notification with the form details and a link to the resume.

The process works perfectly unless the user has a space in the PDF file name. The space ends the link in the email to client and they are unable to retrieve the PDF.

My-Resume.pdf creates a link to clientsite.com/path/My-Resume.pdf. That works fine.

However, uploading My Resume.pdf creates a link to clientsite.com/path/My

Any suggestions on how to get rid of the space?

Thanks!

Author:  DIGI3 [ Wed Jun 10, 2020 8:10 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

You should be able to use |cms_escape:'url' on the filepath variable, so something like:
\$1:
{$myfile|cms_escape:'url'}

will convert my/path/to/file name.pdf to my/path/to/file%20name.pdf

Documentation for Smarty's escape is https://www.smarty.net/docsv2/en/language.modifier.escape

Author:  afrimax1 [ Fri Jun 12, 2020 2:51 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

Great!

But where do I put this code? Where is the relevant filepath variable to change?

Author:  DIGI3 [ Fri Jun 12, 2020 2:59 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

I'm making some assumptions here without knowing your exact setup, but it should do the job. Open the form in CGBetterForms and go to the Handlers tab. One of them is likely an email handler, you can click on it and will see the template used to generate the email. Find the line that generates the link to the file and modify it there.

There are other options - you could rename the file on upload, or during/after form processing, but both of these would require some development knowledge. Encoding the link is probably the easiest.

Author:  afrimax1 [ Thu Jun 25, 2020 2:34 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

thanks for the response and apologies for coming back to this so late. I tried as I understood your suggestion, but cannot get it working.

Installed CGBetterForms and used it fresh out of the box. Created an upload field named 'Resume' to upload resumes. No alterations of any kind to the code. Works perfectly when a PDF file is uploaded with no spaces at all.

to test your suggestion:

1. Went to the CGBetterForms--> the form--> Handlers--> email results to specified addresses

2. Converted {$Resume} line- which works fine for files with no spaces- and tried it as {$Resume|cms_escape:'url'}

It comes back with the full path, but with each special character marked up (spaces, colons, slashes, etc.).

Results also do not come back as a link, just comes back as a plain-text path.

3. Converted escape into a 'href=' but that does not work at all.

Any other suggestions? I feel like we are getting close.

Attachments:
Screenshot- Handlers.jpg
Screenshot- Handlers.jpg [ 130.3 KiB | Viewed 491 times ]

Author:  afrimax1 [ Thu Jun 25, 2020 2:37 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

Here is the email I get.

First result is a broken link.

Second result is plain text.

Third result does not show up as a link.

Attachments:
Screenshot- results.jpg
Screenshot- results.jpg [ 81.62 KiB | Viewed 489 times ]

Author:  DIGI3 [ Thu Jun 25, 2020 2:41 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

The documentation for |cms_escape (which is just a customized version of Smarty's |escape) can be found here: https://www.smarty.net/docs/en/language.modifier.escape.tpl

It's possible I just chose the wrong parameter, try urlpathinfo maybe.

Author:  afrimax1 [ Thu Jun 25, 2020 2:57 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

Got it! Will play around with it. Thank you so much for pointing me in the right direction.

I do think, however, that the module should have this capability built in.

Thank you!

Author:  afrimax1 [ Fri Jun 26, 2020 6:22 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

After trying several different parameters to cms_escape, I still could not get this to work.

Added a bug report to the module, as this should come working out of the box anyhow.

Thanks for the help.

Author:  velden [ Fri Jun 26, 2020 6:51 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

In my opinion the module should return the actual value.

You as the website developer should then properly format it for your specific use.

BTW: note that some email clients try to properly create a link from a string looking like a link. You can't blame the module developer for the mail client failing that.

If you only want to replace spaces then I'd suggest to use

\$1:
{$Resume|replace:' ':'%20'}

Author:  afrimax1 [ Fri Jun 26, 2020 7:06 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

1. I am not blaming the module developer, I am just trying to solve a problem. It does attempt to create a link, but that link is truncated and, therefore, does not work with gmail or outlook.

This is not about blame at all, it is simply attempting to get it to work for my client. I use CGBetterForms on at least 5 sites and it works wonderfully. This is the first time I have had this request and problem.

2. {$Resume|replace:' ':'%20'} WORKED PERFECTLY!

Thank you!

Author:  Dr.CSS [ Fri Jun 26, 2020 9:19 pm ]
Post subject:  Re: CGBetterForms- uploads with spaces

You could also do this to remove all spaces...

|replace:' ':''

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/