Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2008-04-23 13:59:43

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: mem_form - Generic HTTP form processing

jakob, I’ll look in to this sometime this week.

Offline

#26 2008-04-23 14:50:05

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,191
Website

Re: mem_form - Generic HTTP form processing

thanks Manfre, that’d be wonderful.


TXP Builders – finely-crafted code, design and txp

Offline

#27 2008-05-17 03:59:25

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: mem_form - Generic HTTP form processing

jakob,

The Issue was caused by incorrectly clearing out the submitted values when a plugin flagged errors. This has been resolved.

mem_form Latest
mem_form Latest

Offline

#28 2008-09-12 19:11:24

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: mem_form - Generic HTTP form processing

Version 0.5 brings file upload support.

mem_form Latest – Uncompressed
mem_form Latest – Compressed

mem_form_file

This will output an HTML file input field.

  • label string Friendly name for the input field. If set, this will output an HTML <label> tag linked to the input field.
  • name string Input field name.
  • class string CSS class name.
  • break string Separator between label tag and input tag.
  • no_replace int Specifies whether a user can upload another file and replace the existing file that will be submitted on successful completion of the form. If “1”, the file input field will be replaced with details about the already uploaded file.
  • required int Specifies if input is required.
  • size int Size of input field.
  • max_file_size int Maximum size for the uploaded file. Checked server-side.
  • accept string The HTML file input field’s “accept” argument that specifies which file types the field should permit.

Plugin Code Example

register_callback('mem_file_form_submitted', 'mem_form.submit');
function mem_file_form_submitted()
{
	global $mem_form_values;
	dmp($mem_form_values);
	foreach($mem_form_values as $k=>$v)
	{
		// find the uploaded temp file and delete it
		if (is_array($v) && isset($v['tmp_name']) && file_exists($v['tmp_name']))
			unlink($v['tmp_name']);
	}
}
function mem_file_form($atts,$thing='')
{
	return mem_form(array('type'=>'file-form', 'enctype'=>'multipart/form-data'),$thing);
}

Tag Usage

<txp:mem_file_form type="file-form">
<txp:mem_form_text name="file_title" label="Title" required="1" />
<br />
<txp:mem_form_file name="myfile" label="File" />
<br />
<txp:mem_form_submit />
</txp:mem_form>

Offline

#29 2008-09-13 07:36:59

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: mem_form - Generic HTTP form processing

Manfre

Fantastic — now I can think about re-working sed_afu to use this. Thank you.


Steve

Offline

#30 2008-09-13 09:01:07

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: mem_form - Generic HTTP form processing

Nice addition – thanks. Where does the uploaded file go to? A temp folder?

Tested this but continue to get error message “Failed to upload file for field File” with this tag:

<txp:mem_form_file name="myfile" required="0" label="File" break="" accept="jpg" />

Offline

#31 2008-09-13 17:06:31

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: mem_form - Generic HTTP form processing

jstubbs

I’ve hit that error too. Have you added the mandatory enctype="multipart/form-data" to your call to mem_form to enable file uploads?

If that doesn’t do it, you can try this edit the plugin. Look for the following in the mem_form_file() function…

                                        if (is_uploaded_file($fname) and $max_file_size >= filesize($fname))
                                                mem_form_store($name, $label, $_FILES[$name]);
                                        elseif (!is_uploaded_file($fname)) {
                                               $mem_form_error[] = mem_form_gTxt('error_file_failed', array('{label}'=>$hlabel));
                                               $err = 1;
                                        }

… replace it with …

                                        if (is_uploaded_file($fname) and $max_file_size >= filesize($fname))
                                                mem_form_store($name, $label, $_FILES[$name]);
                                        elseif (!is_uploaded_file($fname)) {
                                               if ($required) {
                                                       $mem_form_error[] = mem_form_gTxt('error_file_failed', array('{label}'=>$hlabel));
                                                       $err = 1;
                                               }
                                        }

Hope that helps.


Steve

Offline

#32 2008-09-13 18:40:09

Manfre
Plugin Author
From: North Carolina
Registered: 2004-05-22
Posts: 588
Website

Re: mem_form - Generic HTTP form processing

Thanks Steve. Patch applied and v0.5.1 is available for download.

Jonathan, the file is placed in the folder $tempdir, as dictated by textpattern’s get_uploaded_file function.

Offline

#33 2008-09-13 19:33:41

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: mem_form - Generic HTTP form processing

Mmm. I have this in the mem_form call:

txp:mem_form type="mem_moderation_article" label="" redirect="/my-classifieds/" redirect_form="mem_redirect_form" form_expired_msg="The form has expired. Please try again"

Because I am using this form along with mem_moderation_article, I am not sure how to use this new tag.

Offline

#34 2008-09-13 19:46:50

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: mem_form - Generic HTTP form processing

Manfre wrote:

Jonathan, the file is placed in the folder $tempdir, as dictated by textpattern’s get_uploaded_file function.

Hi Michael. Thanks for the that. So – what is the best way to access the uploaded file? Particularly if the file is attached to a moderated article submission?

Offline

#35 2008-09-14 13:45:26

net-carver
Archived Plugin Author
Registered: 2006-03-08
Posts: 1,648

Re: mem_form - Generic HTTP form processing

Jonathan

So – what is the best way to access the uploaded file? Particularly if the file is attached to a moderated article submission?

Depends what you want to do with it! If you’re just downloading via sftp or something — potentially nothing. If you want it automatically made available for access/download from your TXP installation you’ve got a little more work to do.

AFAIK, you’ll need to use a custom form for mem_moderation_article that includes a mem_form_file entry (and add the enctype to the enclosing mem_form.) After that you’ll need to do some custom handling of the uploaded file to transfer it into the txp files area & DB on successful submission/moderation acceptance of article.

This is essentially what sed_afu has been doing (sans the article stuff.) Now Manfre’s fixed up mem_form, I intend to rewrite sed_afu to use it

In the meantime, if I hit on the answer to your question I’ll let you know!


Steve

Offline

#36 2008-09-16 10:12:01

Sheru
Member
From: Kathmandu, Nepal
Registered: 2007-05-09
Posts: 96

Re: mem_form - Generic HTTP form processing

Dear All,
Greetings!
As I had earlier post regarding fileupload using some textpattern plugin. I was suggested to post on this thread for mem_form plugin.

My requirement: Actually our client need send bigger files using FTP. What I thought is, It would be better for the client(in terms of their convenience) to upload the stuff by going through the website. For this, I would first use ign_password_protect plugin to authenticate the user. If authentication is successful, then user will be shown upload form.

Upload file would be going to public_html/files folder. It’s not necessary to insert into the Txp’s files table. Is this possbile using the mem_form plugin and what about the security risk if yes?

Thank you all for your help
Sheru

Offline

Board footer

Powered by FluxBB