Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2008-02-27 18:20:42

ruud
Developer emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,067
Website

Re: mem_form - Generic HTTP form processing

Shouldn’t it be form="txphorum" instead of type="txphorum" ?

If that is some new feature in mem_form, then you could also do it like this:

<txp:php>echo mem_form(array('type' => 'txphorum', 'redirect' => page_url(array())));</txp:php>

Last edited by ruud (2008-02-27 18:23:41)

Offline

#22 2008-02-28 17:06:39

benbruce
Plugin Author
Registered: 2006-01-13
Posts: 328
Website

Re: mem_form - Generic HTTP form processing

ruud,

I didn’t have everything in a separate form, and that was my issue. Once I made the mem_form tag a self-closing tag (<txp:asy_wondertag><txp:mem_form form="txphorum" redirect="<txp:page_url />" /></txp:asy_wondertag>) it worked perfectly. Thank you,

  • Ben

Offline

#23 2008-02-28 23:16:48

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

Re: mem_form - Generic HTTP form processing

The “type” argument is used by plugins to determine which of the (potentially many) mem_form events they should process.

Offline

#24 2008-04-23 08:57:37

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,887
Website

Re: mem_form - Generic HTTP form processing

I’m trying to validate that two date fields for an event are plausible, e.g. that the event begins in the future and that the end date is after the start date.

I have assembled a working function in a plugin for mem_form that works as desired returning the appropriate errors but with two remaining problems:

  1. The form is correctly redisplayed with the values previously entered but they are lost on resubmitting, e.g. when you correct your false date and resubmit. The form then returns a new set of errors saying that all the other values are missing.
  2. How do I add the isError class to the relevant fields so that they can be highlighted?

The relevant section of the form that is called from txp:mem_moderation_article_form is as follows (including format="..." for regex pattern to match YYYY-MM-DD date format):

<txp:mem_form_text		name="custom_2"	label="Begin Date" 
						required="1" break="" class="short" 
						example="(YYYY-MM-DD)" 
						format="/^(20[0-9]{2})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/" 
						/>

<txp:mem_form_text		name="custom_3"	label="End Date" 
						required="1" break="" class="short" 
						example="(YYYY-MM-DD)" 
						format="/^(20[0-9]{2})-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/" 
						/>

The plugin function hooks into the mem_form.submit callback and is as follows:

// callback for validating date plausibility
register_callback('jcr_memform_validate_date','mem_form.submit');

// new function - date validation

function jcr_memform_validate_date() {

	global $mem_form_error, $isError;

	$begin_date  = strtotime(trim(ps('custom_2')));
	$end_date    = strtotime(trim(ps('custom_3')));
	$todays_date = strtotime(date('Y-m-d'));

	// if end date is before start date
	if ($end_date < $begin_date) {
	    $mem_form_error[] = 'The specified end date lies before the begin date. Please check your details.';
	    $isError = "errorElement";
	} 

	// if start date is in the past
	if ($begin_date < $todays_date ) {
	    $mem_form_error[] = 'The specified start date lies in the past. Please check your details.';
	    $isError = "errorElement";
	}
	return;
}

BTW: I’m using the svn versions of mem_moderation and mem_form from http://manfre.net/svn/txp/.

I’m sure I’m missing something simple that retains the form session. Any help much appreciated.


TXP Builders – finely-crafted code, design and txp

Offline

#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
Moderator
From: Germany
Registered: 2005-01-20
Posts: 2,887
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
Member
From: UK
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
Textile | My plugins on GitHub | @netcarver

Offline

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

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,392
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

Board footer

Powered by FluxBB