Textpattern Forum

You are not logged in. Register | Login | Help

#31 2009-07-16 21:51:40

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 1,943
Website

Re: mem_simple_form

I’m not all too familiar with mem_simple_form but have done more normal implementations. What you’re trying to do sounds interesting and I’d like to know what the solution is. Two long shots as “to try” ideas:

  • Do you have a field custom_13 in your textpattern table? Does it work if you stay within the 10 normally provided by txp?
  • Maybe it’s a problem with a nonce-mismatch caused by chaining the forms. Each form creates a random nonce, then tests against it on submission (if I’ve understood it correctly, a security measure that is meant to bar spoofed form submissions from elsewhere). Maybe the nonces from both forms get in a tangle. I don’t know the plugin or process well enough to check but one could try and follow the source or echo out the nonce to see? A long shot but might explain it.

BTW is the category created in the first step? The lft and rgt seem to be the relative position of the plugin in the tree, so shouldn’t theoretically be random. That shouldn’t stop it being created, though. Not sure off hand how you’d generate that using mem_simple_form. Similar story with the name too, which is a sanitised version of the title. Also, what happens with the success_form from your first step. Does that lead right into the second?


TXP Builders – finely-crafted code, design and txp

Offline

#32 2009-07-17 04:17:10

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: mem_simple_form

jakob wrote:

I’m not all too familiar with mem_simple_form but have done more normal implementations. What you’re trying to do sounds interesting and I’d like to know what the solution is.

Thanks for your interest and support!

Two long shots as “to try” ideas:

— Do you have a field custom_13 in your textpattern table? Does it work if you stay within the 10 normally provided by txp?

Yes, I’m using glz_custom_fields because the site requires extra data fields. But I get the exact same results with any custom field number. My guess is that mem_simple_form is agnostic when it comes to Textpattern’s normal schema— it uses MySQL to jam input directly into the existing database fields.

— Maybe it’s a problem with a nonce-mismatch caused by chaining the forms. Each form creates a random nonce, then tests against it on submission (if I’ve understood it correctly, a security measure that is meant to bar spoofed form submissions from elsewhere). Maybe the nonces from both forms get in a tangle.

That sounds like a very reasonable lead.

I don’t know the plugin or process well enough to check but one could try and follow the source or echo out the nonce to see? A long shot but might explain it.

That could be. Detailed nonce information is included in the tag-trace, but I can’t make anything of it; I’ve included a tag-trace below for each step.

The lft and rgt seem to be the relative position of the plugin in the tree, so shouldn’t theoretically be random. That shouldn’t stop it being created, though. Not sure off hand how you’d generate that using mem_simple_form. Similar story with the name too, which is a sanitised version of the title.

Using the randuid works— it creates a unique entry for each category posted through the form. There are caveats though: it messes up the category tree in Textpattern’s “Categories” tab under “Content”. It also leads to meaningless category-names. None of these have any effect on the user-experience of regular site visitors, but it would be nice to find a better way eventually.

BTW is the category created in the first step? … Also, what happens with the success_form from your first step. Does that lead right into the second?

Yes, STEP 1 successfully creates a new entry in the txp_category table, and the success_form renders along with second form.

Here’s what seems to be going on in more detail:

1. When Textpattern first loads the page, mem_simple_if_ps finds no data posted to the custom_13 field, which only exists in STEP 2, so it loads STEP 1— as it should. Here’s the tag-trace:

<txp:mem_simple_if_ps name="string_custom_13">
	[<txp:mem_simple_if_ps name="string_custom_13">: false]
	<txp:mem_simple_form table="txp_category" id_field="id" id_insert="0" success_form="_category-confirm">
		[SQL (0.000249147415161): insert into txp_discuss_nonce set issue_time = now(), nonce = 'd79ef345b6577bd1aed2468a7203aed4']
		<txp:variable name="site_search-url" />
		<txp:mem_form_secret name="string_type" value="article" />
		<txp:mem_form_secret name="string_parent" value="root" />
		<txp:mem_form_text name="string_title" label="Category" />
		<txp:mem_form_secret name="randuid_name" />
		<txp:mem_form_secret name="randuid_lft" />
		<txp:mem_form_secret name="randuid_rgt" />
		<txp:mem_form_submit label="Next" />
		<txp:mem_form_secret name="mem_simple_table" value="txp_category" />
		<txp:mem_form_secret name="mem_simple_id_field" value="id" />
		<txp:mem_form_secret name="mem_simple_id_insert" value="0" />
		<txp:mem_form_secret name="mem_simple_ignore_fields" value="" />
		<txp:mem_form_secret name="mem_simple_success_form" value="_category-confirm" />
	</txp:mem_simple_form>
</txp:mem_simple_if_ps>
<txp:mem_simple_if_ps name="randuid_name">
	[<txp:mem_simple_if_ps name="randuid_name">: false]
</txp:mem_simple_if_ps>

2. After a string is entered in STEP 1 and submitted, a new entry appears in the txp_category table.

Textpattern renders the STEP 1’s success_form.

mem_simple_if_ps finds that a randuid was posted to the category name and now renders the form for STEP 2, as it should. So far, so good!

Here’s the tag-trace at this point:

<txp:mem_simple_if_ps name="string_custom_13">
	[<txp:mem_simple_if_ps name="string_custom_13">: false]
	<txp:mem_simple_form table="txp_category" id_field="id" id_insert="0" success_form="_category-confirm">
		[SQL (0.0017728805542): delete from txp_discuss_nonce where issue_time < date_sub(now(), interval 10 minute)]
		[SQL (0.000212907791138): select used from txp_discuss_nonce where nonce = 'd79ef345b6577bd1aed2468a7203aed4']
		<txp:variable name="site_search-url" />
		<txp:mem_form_secret name="string_type" value="article" />
		<txp:mem_form_secret name="string_parent" value="root" />
		<txp:mem_form_text name="string_title" label="Category" />
		<txp:mem_form_secret name="randuid_name" />
		<txp:mem_form_secret name="randuid_lft" />
		<txp:mem_form_secret name="randuid_rgt" />
		<txp:mem_form_submit label="Next" />
		<txp:mem_form_secret name="mem_simple_table" value="txp_category" />
		<txp:mem_form_secret name="mem_simple_id_field" value="id" />
		<txp:mem_form_secret name="mem_simple_id_insert" value="0" />
		<txp:mem_form_secret name="mem_simple_ignore_fields" value="" />
		<txp:mem_form_secret name="mem_simple_success_form" value="_category-confirm" />
		[SQL (0.000283002853394): update txp_discuss_nonce set used = '1', issue_time = now() where nonce = 'd79ef345b6577bd1aed2468a7203aed4']
		[SQL (0.000200986862183): insert into txp_category set type = 'article', parent = 'root', title = 'Category 24601', name = '0643b0585a883553b48465d365fe2ac6', lft = 'b4b912efdb8be93ecdfb09ccc2b97627', rgt = '4114e0d51b0dd0d962f936b4f2ab1ac6']
		[SQL (0.000200986862183): select Form from txp_form where name='_category-confirm']
		[Form: _category-confirm]
		<txp:hide>
		</txp:hide>
	</txp:mem_simple_form>
</txp:mem_simple_if_ps>
<txp:mem_simple_if_ps name="randuid_name">
	[<txp:mem_simple_if_ps name="randuid_name">: true]
	<txp:mem_simple_form table="textpattern" id_field="ID" id_insert="0" success_form="_record-confirm">
		[SQL (0.000212907791138): insert into txp_discuss_nonce set issue_time = now(), nonce = 'e88d2dc41f4fc9e6e7da8cd68b43e430']
		<txp:mem_form_secret name="int_Annotate" value="1" label="Comments On" />
		<txp:mem_form_secret name="string_section" value="category-info" label="Section" />
		<txp:mem_form_secret name="string_category1" value='<txp:mem_simple_ps name="randuid_name" />' label="Category" />
			[attribute 'value']
			<txp:mem_simple_ps name="randuid_name" />
			[/attribute]
		<txp:mem_form_secret name="string_title" value='<txp:mem_simple_ps name="string_title" />' />
			[attribute 'value']
			<txp:mem_simple_ps name="string_title" />
			[/attribute]
		<txp:mem_form_secret name="now_posted" value="" />
		<txp:mem_form_secret name="string_AuthorID" value='<txp:ign_user_info type="name" />' label="Author" />
			[attribute 'value']
			<txp:ign_user_info type="name" />
			[/attribute]
		<txp:mem_simple_ps name="string_title" />
		<txp:mem_form_select name="string_custom_13" label="Select something" items="option 1, option 2, option 3" values="option 1, option 2, option 3" />
		<txp:mem_form_submit />
		<txp:mem_form_secret name="mem_simple_table" value="textpattern" />
		<txp:mem_form_secret name="mem_simple_id_field" value="ID" />
		<txp:mem_form_secret name="mem_simple_id_insert" value="0" />
		<txp:mem_form_secret name="mem_simple_ignore_fields" value="" />
		<txp:mem_form_secret name="mem_simple_success_form" value="_record-confirm" />
	</txp:mem_simple_form>
</txp:mem_simple_if_ps>

3. This where things go a little haywire.

After an option from STEP 2 is selected and submitted, something encouraging happens: the very first mem_simple_if_ps detects a string posted to the custom_13 field and displays it with the mem_simple_ps tag. Textpattern knows that something was posted in STEP 2, and it remembers.

But there are three things that fail to appear at this point:

  1. No record is added to the textpattern table by the form.
  2. No success_form is rendered from STEP 2.
  3. No error message appears to tell us what went wrong.

Here is the final tag-trace:

<txp:mem_simple_if_ps name="string_custom_13">
	[<txp:mem_simple_if_ps name="string_custom_13">: true]
	<txp:mem_simple_ps name="string_custom_13" />
</txp:mem_simple_if_ps>
<txp:mem_simple_if_ps name="randuid_name">
	[<txp:mem_simple_if_ps name="randuid_name">: false]
</txp:mem_simple_if_ps>
<txp:mem_simple_if_ps name="randuid_name">
	[<txp:mem_simple_if_ps name="randuid_name">: false]
</txp:mem_simple_if_ps>

Thanks again for your suggestions! If you have further ideas, even php to run to get more debug info, I’m all ears!

EDIT: Removed screengrab images, since the problem is resolved.

Last edited by johnstephens (2009-07-30 00:40:43)

Offline

#33 2009-07-17 07:48:58

jakob
Moderator
From: Germany
Registered: 2005-01-20
Posts: 1,943
Website

Re: mem_simple_form

I’ve sent you a mail with some loose ideas of things to try that would otherwise clog things up here.


TXP Builders – finely-crafted code, design and txp

Offline

#34 2009-07-17 14:25:34

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: mem_simple_form

Bwuhahahahah! I had an epiphany as I woke up this morning, and it worked— I’ll post the solution once I get to work.

Offline

#35 2009-07-17 17:45:04

johnstephens
Plugin Author
From: Harrisonburg, VA
Registered: 2008-06-01
Posts: 834
Website

Re: mem_simple_form

So, comparing the tag traces I posted last night got me thinking. This is an issue in which Textpattern logic is doing exactly what it’s told, without regard for my wishes. This issue is aggravated by the way I’ve been thinking about the problem and the behavior I want.

I noticed a specific difference between the two instances of mem_simple_form: the form in STEP 1 renders twice. First mem_simple_form shows us the input fields, and then it shows us the success_form.

But the form in STEP 2 only shows up once— when the input fields are rendered. The last tag-trace I posted shows why:

<txp:mem_simple_if_ps name="randuid_name">
	[<txp:mem_simple_if_ps name="randuid_name">: false]
</txp:mem_simple_if_ps>

Before rendering mem_simple_form, Textpattern is checking for data posted in the randuid_name field, which is posted from the form in STEP 1. But after STEP 2 is posted, that data is no longer there, and Textpattern evaluates the condition as false, and doesn’t render the success_form.

Changing the conditional to check for string_title, which is posted by both forms, this problem evaporated1. Oh, and one other thing:

<txp:mem_form_secret name="string_title" value='<txp:mem_simple_ps name="string_title" />' />

mem_simple_if_ps doesn’t check secret fields, so I had to change it:

<txp:mem_form_hidden name="string_title" value='<txp:mem_simple_ps name="string_title" />' />

One of the aggravating issues was calling form one “STEP 1” and the second form “STEP 2”— this language clouded the fact that each mem_simple_form must render in two steps in order to work!

Now the only issue is how to generate appropriate lft, rgt, and name values for category input, which is probably beyond the scope of this plugin’s thread— sounds like a job for <txp:php>.

Thanks again for your guidance, suggestions, and pointed questions that forced me to think more critically!

1 If there wasn’t a field in common posted by each form, I could have used <txp:variable /> to test for one or the other.

Offline

#36 2009-11-13 13:33:10

sev
New Member
Registered: 2009-11-13
Posts: 1

Re: mem_simple_form

Hello!

A very fine plugin, that helped me a lot. Nice work.

I’m only struggling with one problem:

The form can be submitted again and again via reloading the page. Seems that the “nonce” protection does not work like in zem_reborn. This is a mayor issue cause vistors can easily spam the database.

Here my code (which is inserted into an article):

<txp:mem_simple_form table="xmas" thanks="Ihr Tipp wurde gespeichert. Viel Glück!" > <p><txp:mem_form_text name="string_vorname" label="Vorname" max="100" required="1" /></p> <p><txp:mem_form_text name="string_nachname" label="Nachname" max="100" required="1" /></p> <p><txp:mem_form_text name="string_strasse" label="Strasse" max="100" required="1" /></p> <p><txp:mem_form_text name="string_hausnummer" label="Nr." max="4" required="1" /></p> <p><txp:mem_form_text name="string_plz" label="PLZ" max="5" required="1" /></p> <p><txp:mem_form_text name="string_ort" label="Ort" max="100" required="1" /></p> <p><txp:mem_form_text name="int_tipp" label="Mein Tipp in cm" max="5" required="1" format="/^[0-9]*$/" /></p> <p style="margin: 30px 0 0 5px"><txp:mem_form_submit label="Speichern und Tipp abgeben" /></p> </txp:mem_simple_form>

Any suggestions on this issue?

cheers,
Sev

Offline

#37 2009-11-20 22:39:28

aslsw66
Member
From: Geneva, Switzerland
Registered: 2004-08-04
Posts: 322
Website

Re: mem_simple_form

I’m returning to TXP after a break of many years…

I have just installed this plugin but I get some error messages before I even try to ushttp://forum.textpattern.com/post.php?action=post&tid=28386e the tags!

These are the errors I’m getting:

A problem occured while loading the plugin: mem_simple_form -> User_Error: Unable to include required plugin "mem_form" on line 498
C:\xampp\xampp\htdocs\textpattern\lib\txplib_misc.php:498 trigger_error()
C:\xampp\xampp\htdocs\textpattern\lib\txplib_misc.php(594) : eval()'d code:60 require_plugin()
C:\xampp\xampp\htdocs\textpattern\lib\txplib_misc.php:594 eval()
C:\xampp\xampp\htdocs\textpattern\publish.php:117 load_plugins()
C:\xampp\xampp\htdocs\index.php:44 include()

I’m setting this up on a development site sitting on XAMPPP. The only other plugins I’m using are:

  • ign_password_protect
  • smd_admin_themes
  • zem_contact_reborn
  • zem_contact_lang

The error message appears regardless of whether I have logged in or not.

Not a good start (I can’t even start to get my hands dirty – and then I will really have some questions).

Any idea what could be generating these errors? Apart from this minor problem, this plugin looks like it will neatly plug a requirement for me.

Thanks

Offline

#38 2009-11-20 22:41:20

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

Re: mem_simple_form

A problem occured while loading the plugin: mem_simple_form -> User_Error: Unable to include required plugin “mem_form” on line 498

Offline

#39 2009-11-20 22:43:57

aslsw66
Member
From: Geneva, Switzerland
Registered: 2004-08-04
Posts: 322
Website

Re: mem_simple_form

When it says “user error”, does that mean me? ie. something I have done? It’s possible of course, as I’m still feeling my way around TXP, but I have barely touched anything apart from the plugins I mentioned.

Offline

#40 2009-11-20 23:02:32

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,191
Website

Re: mem_simple_form

You just need the mem_form plugin as well which is a requirement of mem_simple_form


My Plugins

Piwik Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

Board footer

Powered by FluxBB