Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#11 2008-02-26 19:22:04
- kelsta
- New Member
- Registered: 2006-05-31
- Posts: 7
Re: mem_form - Generic HTTP form processing
Thanks Michael,
hooking into the submit callback is obviously where I should be acting on the data. Cheers for pointing me in the right direction, I think I’ve got a handle on that now.
Am I right in thinking that with the display event I can add HTML to the form at either the beginning or the end, based on the $pre value? Is there any way of replacing a tag on a page from within a callback in Texttpattern? Ie. can I put something in the middle of the form and have the callback replace that with something else?
Also, am I right that using the callback to programmatically add fields, I still can’t add <txp:mem_form…> tags and pull out the data from the $mem_form_values[] array? As they’re not procecced I’ll still have to work with $_POST to get the values from the extra fields I add? That seems to be the result I get if I add mem_form tags from my display callback.
Cheers for your help,
Alex
Offline
#12 2008-02-26 19:29:16
- Gocom
- Plugin Author
- From: Helsinki, Finland
- Registered: 2006-07-14
- Posts: 4,533
- Website
Re: mem_form - Generic HTTP form processing
Am I right in thinking that with the display event I can add HTML to the form at either the beginning or the end, based on the $pre value? Is there any way of replacing a tag on a page from within a callback in Texttpattern? Ie. can I put something in the middle of the form and have the callback replace that with something else?
By making plugin & function ;) tags are always replaced with functions (or custom parser with plugin).
$_POST to get the values from the extra fields I add? That seems to be the result I get if I add mem_form tags from my display callback.
With plugin you can get them easily, in example with ps('name_of_the_field');
or extract(psa('name1','name2'));
or by just calling the function as Manfre said.
Offline
#13 2008-02-26 19:55:24
- Manfre
- Plugin Author
- From: North Carolina
- Registered: 2004-05-22
- Posts: 588
- Website
Re: mem_form - Generic HTTP form processing
Am I right in thinking that with the display event I can add HTML to the form at either the beginning or the end, based on the $pre value? Is there any way of replacing a tag on a page from within a callback in Texttpattern? Ie. can I put something in the middle of the form and have the callback replace that with something else?
Correct. $pre 1 is before and $pre 0 is after the mem_form input tags. If you need more control over where text is positioned, I’d recommend using CSS and jQuery to shuffle it around. If you replacing text, then mem_form will not be able to process it properly.
Also, am I right that using the callback to programmatically add fields, I still can’t add <txp:mem_form…> tags and pull out the data from the $mem_form_values[] array? As they’re not procecced I’ll still have to work with $_POST to get the values from the extra fields I add? That seems to be the result I get if I add mem_form tags from my display callback.
Are you trying to access $mem_form_values[] from within the display callback or from the submit callback? Is there anything in the array? Did you declare it as a global in your function?
Offline
#14 2008-02-26 20:13:19
- kelsta
- New Member
- Registered: 2006-05-31
- Posts: 7
Re: mem_form - Generic HTTP form processing
I added a diplay call back which adds some extra checkboxes to the form like this
$tag = "";
$skillAreas = safe_rows('*', 'skill_areas', 'true');
foreach ($skillAreas as $skillArea)
{
$tag .= "<txp:mem_form_checkbox name=\"".$skillArea['skill']."\" label=\"".$skillArea['long_name']."\" break=\"\" required=\"0\" /><br />\n";
}
return $tag;
Then in the submit callback I have
global $mem_form_values;
foreach($mem_form_values as $key => $value) {
echo $key . “ “ .$value.”<br />”;
}
But the values of the extra checkboxes aren’t in the array.
Looking at the debugging section of the source for the produced form, the added mem_form_chackbox tags come after the [secondpass]
Offline
#15 2008-02-26 20:50:53
- ruud
- Developer emeritus
- From: a galaxy far far away
- Registered: 2006-06-04
- Posts: 5,068
- Website
Re: mem_form - Generic HTTP form processing
kelsta, I think your initial approach using inline PHP was better, but you should do something like this:
<txp:php>
$skillAreas = safe_rows('*', 'skill_areas', 'true');
foreach ($skillAreas as $skillArea)
{
echo mem_form_checkbox(
array(
'name' => $skillArea['skill'],
'label' => $skillArea['long_name'],
'break' => "",
'required' => 0
)
). "<br />\n";
}
</txp:php>
Offline
#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
#17 2008-02-27 16:55:36
- ruud
- Developer emeritus
- From: a galaxy far far away
- Registered: 2006-06-04
- Posts: 5,068
- Website
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
#18 2008-02-27 17:04:11
- benbruce
- Plugin Author
- Registered: 2006-01-13
- Posts: 328
- Website
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
#19 2008-02-27 17:14:29
- ruud
- Developer emeritus
- From: a galaxy far far away
- Registered: 2006-06-04
- Posts: 5,068
- Website
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
#20 2008-02-27 17:46:54
- benbruce
- Plugin Author
- Registered: 2006-01-13
- Posts: 328
- Website
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