Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2009-04-16 02:46:39

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: mem_simple_form

Manfre wrote:

Do all of the steps use the same url?

Yes— Step one is at example.dev/section/

When I click submit, the success-form with Step-2 loads, appending a string to the url like so:

example.dev/my-section/#mem24251a6b5ac2e0880d55a5affabcd39a

When I click submit on Step-2, a new string appears, but no success-form:

example.dev/my-section/#memcc4d59f633db8d9ca9df8cb1f54a5522

If so, that might explain why the first step is being loaded instead of your third step.

Is there a way to make the success-form load at a different url? If so, that would probably solve the problem.

Thank you again!

Offline

#26 2009-04-16 13:47:32

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

Re: mem_simple_form

Is there a way to make the success-form load at a different url? If so, that would probably solve the problem.

No, i’m just trying to get a handle of how you are using the forms. You should have each form set a hidden field that identifies which form should be rendered. Each form should be guarded by a conditional tag that checks for the appropriate hidden field to prevent the other 2 from loading.

Offline

#27 2009-04-19 03:44:48

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: mem_simple_form

Manfre wrote:

You should have each form set a hidden field that identifies which form should be rendered. Each form should be guarded by a conditional tag that checks for the appropriate hidden field to prevent the other 2 from loading.

That sounds interesting, but I’m not sure what conditional to use or where.

I’m just trying to get a handle of how you are using the forms.

Here are my forms:

Step 1

<txp:mem_simple_form table="txp_category" id_field="id" id_insert="0" success_form="step-2">
<txp:mem_form_secret name="string_type" value="article" />
<txp:mem_form_secret name="string_parent" value="root" />
<fieldset id="add-cat-info">
	<legend>Add a Category</legend>
	<div>
	<txp:mem_form_text name="string_title" label="Title of Category" />
	<txp:mem_form_secret name="randuid_name" />
	<txp:mem_form_secret name="randuid_lft" />
	<txp:mem_form_secret name="randuid_rgt" />
	</div>
</fieldset>
<txp:mem_form_submit label="Next" />
</txp:mem_simple_form>

Step 2

<txp:mem_simple_if_ps name="string_title">
<txp:mem_simple_form table="textpattern" id_field="ID" id_insert="0" Annotate="1" success_form="step-3">
<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="string_title" />' label="Category" />
<txp:mem_form_secret name="string_title" value='<txp:mem_simple_ps name="string_title" />' />
<txp:mem_form_secret name="now_posted" value="" />
<txp:mem_form_secret name="string_AuthorID" value='<txp:ign_user_info type="name" />' label="Author" />
<fieldset>
	<legend>About <txp:mem_simple_ps name="string_title" /></legend>
	<div>
		<txp:mem_form_select name="string_custom_13" label="Some Metadata" items="option 1,option 2,option 3" values="option1,option2,option3" />	
	</div>
</fieldset>
<txp:mem_form_submit />
</txp:mem_simple_form>
</txp:mem_simple_if_ps>

Step 3

<h1>Confirmation</h1>

As I said, Step 2 loads successfully upon submitting Step 1, and the simple_ps data is successfully transfered from the user input of Step 1 into Step 2. But when I submit Step 2, nothing happens in the system— I don’t get a new article, and Step 3 doesn’t appear. Instead, I see Step 1 again.

I have tried wrapping the Confirmation header in Step 3 with <txp:mem_simple_if_ps> and <txp:mem_simple_if_ps name="string_title">, but the behavior is the same.

I can see setting a txp:variable with a hidden field and checking the value before rendering the forms, but it seems like the primary issue is that no data goes into the textpattern table when submitting Step 2; since it’s not a success, the success form indicated doesn’t render. Step 2 renders correctly, but it does not send anything to the database.

Maybe I’m wrong. Will this plugin let me submit input from a form rendered as the success_form of previous input? If so, where is the flaw in my markup?

Thank you again for your magnificent support!

Last edited by johnstephens (2009-07-13 19:25:11)

Offline

#28 2009-05-04 19:25:06

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: mem_simple_form

Any ideas on this?

Offline

#29 2009-07-16 18:13:53

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: mem_simple_form

Okay, I’ve simplified my code significantly, and I think this may help to isolate the problem. this is my form, with comments:

<!--
Check if data from STEP 2 was posted.
-->
<txp:mem_simple_if_ps name="string_custom_13">
<!--
We have data from STEP 2.
-->
<h1>Here is your data from STEP 2: <txp:mem_simple_ps name="string_custom_13" /></h1>
<txp:else />
<!--
We have NO data from STEP 2.

Render STEP 1: Category Input form.
-->
<txp:mem_simple_form table="txp_category" id_field="id" id_insert="0" success_form="_category-confirm">
<!--
This form adds an entry to the txp_category table
as specified above.
-->

<h1>STEP 1: Category Input form</h1>
<txp:mem_form_secret name="string_type" value="article" />
<fieldset id="add-category-info">
	<legend>Add a Category</legend>
	<div>
	<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" />
<!--
These fields are required to successfully post a
category. This method is passing random unique
strings into these fields.

There must be a cleaner way to generate lft and
rgt and category name, but I will post a new
thread for these questions.
-->
	<txp:mem_form_secret name="string_parent" value="root" />
	</div>
</fieldset>
<txp:mem_form_submit label="Next" />
</txp:mem_simple_form>
</txp:mem_simple_if_ps>

<!--
Check if data from STEP 1 was posted.
-->
<txp:mem_simple_if_ps name="randuid_name">
<!--
We have data from STEP 1.

Render STEP 2: Article Input form.
-->
<txp:mem_simple_form table="textpattern" id_field="ID" id_insert="0" success_form="_record-confirm">
<!--
This form adds an entry to the textpattern table
as specified above.
-->

<h1>STEP 2: Article Input form</h1>
<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" />
<!--
We want to categorize this article under the
category created in STEP 1.

Here, we pass the category name into a hidden
category field.
-->

<txp:mem_form_secret name="string_title" value='<txp:mem_simple_ps name="string_title" />' />
<!--
The article will have the same title as the
category.
-->

<txp:mem_form_secret name="now_posted" value="" />
<txp:mem_form_secret name="string_AuthorID" value='<txp:ign_user_info type="name" />' label="Author" />
<!--
Enter the author name from the current ign_user.
-->
<fieldset>
	<legend>
		About <txp:mem_simple_ps name="string_title" />
	</legend>
	<div>
		<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" />
	</div>
</fieldset>
<txp:mem_form_submit />
</txp:mem_simple_form>
</txp:mem_simple_if_ps>

I’m no longer loading STEP 2 in the success_form of STEP 1.

Last edited by johnstephens (2009-07-16 20:27:31)

Offline

#30 2009-07-16 20:27:42

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: mem_simple_form

Here are the results.

  1. When I load the page in my browser, I immediately see the input form for STEP 1, since it doesn’t see any data from STEP 2.
  2. After I complete STEP 1 and click submit, STEP 1’s success_form renders, AND I see the input form for STEP 2. The form seems to correctly load all the information it needs that was submitted in STEP 1.
  3. When the second form submits, I see *Here is your data from STEP 2: option x*— which shows that textpattern recognizes data was submitted from STEP 2.
  4. However, STEP 2’s success_form does NOT render, and NO RECORD is added to the textpattern table. There is also no error message from mem_simple_form.

Can anyone see where I’ve made a mistake in my markup, logic, or anywhere else?

I’d love to hear any guidance, support, suggestions, or feedback. Please let me know what you think.

Offline

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

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,577
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: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
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
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,577
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: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
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: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
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

Board footer

Powered by FluxBB