[Eis-commits] SF.net SVN: eis: [226] trunk/lib/base/element.lib.php
Status: Pre-Alpha
Brought to you by:
baslijnse
|
From: <bas...@us...> - 2008-02-24 14:40:49
|
Revision: 226
http://eis.svn.sourceforge.net/eis/?rev=226&view=rev
Author: baslijnse
Date: 2008-02-24 06:40:44 -0800 (Sun, 24 Feb 2008)
Log Message:
-----------
Added a 'prefix' and 'unprefix' method to the element base class for adding unique prefixes to formfields
Modified Paths:
--------------
trunk/lib/base/element.lib.php
Modified: trunk/lib/base/element.lib.php
===================================================================
--- trunk/lib/base/element.lib.php 2008-01-03 22:13:20 UTC (rev 225)
+++ trunk/lib/base/element.lib.php 2008-02-24 14:40:44 UTC (rev 226)
@@ -66,6 +66,35 @@
$this->e->session->save();
return is_array($post) ? $post : array();
}
+
+ /**
+ * Prefixes a form input name with the element's id to make it unique
+ */
+ function prefix($formname) {
+ return 'e-'.$this->getId().'-'.$formname;
+ }
+ /**
+ * Strips the prefix from a form input name if it has been prefixed with the 'prefix' method
+ */
+ function unprefix($formname) {
+ $id = 'e-'.$this->getId().'-';
+
+ if(strpos($formname,$id) === 0) {
+ return substr($formname, strlen($id));
+ } else {
+ return $formname;
+ }
+ }
+ /**
+ * Strips the prefix for an entire form
+ */
+ function unprefixForm($form) {
+ $new = array();
+ foreach($form as $k => $v) {
+ $new[$this->unprefix($k)] = $v;
+ }
+ return $new;
+ }
/**
*DEPRECATED
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|