Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#16 2008-02-27 14:33:06
- kelsta
- New Member
- Registered: 2006-05-31
- Posts: 7
Re: mem_form - Generic HTTP form processing
Thanks ruud, calling the mem_form functions directly like that works a treat to allow me to add elements to my form programatically.
Just a couple of little niggles left. If I add some radio buttons to the form, setting group=“sameGroupName” and name=“differentValue” for each button, I don’t get a radio button group on the page. Any and all of the buttons in the group can be selected individually. Is this a bug or am I misunderstanding how this element is supposed to work?
Secondly, it’d be nice to be able to add a checkbox group to the form using the name=“groupName[]” value=“differentValues” syntax and then access all the values from those checkboxes as an array on the server side. Not quite sure how that’d work with the code that saves the values to mem_form_values[] off the top of my head. It’d be a nice addition if it’s possible though.
Offline
Re: mem_form - Generic HTTP form processing
That’s the correct way to use radio buttons, yes, assuming that part of mem_form is still identical to ZCR.
Check the resulting HTML code to see if the name of those input tags is the same for all radio buttons in one group.
Offline
Re: mem_form - Generic HTTP form processing
I’m trying to use the redirect="' attribute to refresh the page. ie, something like:
<txp:asy_wondertag><txp:mem_form type="form" redirect="<txp:permlink />" /></txp:asy_wondertag>
But that’s not working. I’m using <txp:asy_wondertag> around particular mem_form inputs, but around the actual mem_form tag it breaks. Is there an easier way to do this?
Thanks,
- Ben
Offline
Re: mem_form - Generic HTTP form processing
Try using the <txp:page_url /> tag instead of <txp:permlink />. The redirect attribute expects a location to the textpattern root directory, not a full URL.
Offline
Re: mem_form - Generic HTTP form processing
thanks for your help, Ruud. Using <txp:page_url /> got me a bit closer, but not there yet. Here’s the code I’m using:
<txp:asy_wondertag><txp:mem_form type="txphorum" redirect="<txp:page_url />" /></txp:asy_wondertag>
And here’s the error message I’m getting:
tag_error <txp:mem_form type="txphorum" redirect="/txphorum/not-logged-in" /> -> Textpattern Warning: Argument not specified for mem_form tag on line 103
which is coming from this section of the plugin:
if (empty($type) or (empty($form) && empty($thing))) {
trigger_error('Argument not specified for mem_form tag', E_USER_WARNING);
return '';
}
I should add that if I remove the <txp:ay_wondertag> and hardcode a redirect (redirect="/url") the form works fine. It’s something about the wondertag around the form function itself (because it works around individual form inputs inside the form no problem). Is there another way to get the page_url into the form variables?
Last edited by benbruce (2008-02-27 18:09:59)
Offline
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
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
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
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:
- 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.
- 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
Re: mem_form - Generic HTTP form processing
jakob, I’ll look in to this sometime this week.
Offline
Re: mem_form - Generic HTTP form processing
thanks Manfre, that’d be wonderful.
TXP Builders – finely-crafted code, design and txp
Offline
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.
Offline
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
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