Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Keeping form data when there is an error

Quote Reply
Keeping form data when there is an error
I have a plugin with that has it's own data table and form template.
When a user submits the form with a missing required field, it takes me back
to the form with the error message, but the custom fields are being erased.

How do I re-fill in the form with already entered data?

Thank you,
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Keeping form data when there is an error In reply to
In the form template you need to make sure that you have the value fields filled in with if tags - for example:

<input type="text" name="Surname" value="<%if Surname%><%Surname%><%endif%>"/>

and then in the script that is processing the form, make sure that you feed the variables back in when you display the error template - for example:

print Links::SiteHTML::display('template_name', { %$variables, main_title_loop => $mtl, error => $error });
Quote Reply
Re: [afinlr] Keeping form data when there is an error In reply to
I actually had the script part setup properly, but in my template,
I was making the following mistake, and it took me a while to
figure it out. So this is just a reminder and/or tip for anyone else.

When using (input type ="text"), the value goes in the <input ...> tag.
<input type="text" name="Surname" value="<%if Surname%><%Surname%><%endif%>"/>

When using (textarea id="Surname"), the value goes between the open and close textarea tags.
<textarea id="Surname" name="Surname" rows="3" cols="42"><%if Surname%><%escape_html Surname%><%endif%></textarea>

FYI, I was using textarea, and putting the value in the opening textarea tag... boo!
It looks like value is in there properly, but it is wrong. Just very hard to notice. <g>
So, don't make this mistake. This example is broken, but at a glance looks correct.
<textarea id="Surname" name="Surname" value="<%if Surname%><%Surname%><%endif%>" rows="3" cols="42"></textarea>

Basic html, duh. Couldn't see the forest through the trees.

Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com