<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://labs.echoditto.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>EchoDitto Labs - making profile.module appear in places it doesn&amp;#039;t want to - Comments</title>
 <link>http://labs.echoditto.com/profile-module-form-wrapper</link>
 <description>Comments for &quot;making profile.module appear in places it doesn&#039;t want to&quot;</description>
 <language>en</language>
<item>
 <title>having some trouble getting</title>
 <link>http://labs.echoditto.com/profile-module-form-wrapper#comment-3865</link>
 <description>&lt;p&gt;having some trouble getting this to work..made a module called mymodule, enabled it and made the call:&lt;/p&gt;
&lt;p&gt;?php print drupal_get_form(&#039;mymodule_profile_form&#039;,&#039;About Me&#039;)?&amp;gt;&lt;/p&gt;
&lt;p&gt;all i get is a submit button!&lt;/p&gt;
&lt;p&gt;any help would be greatly appreciated.&lt;/p&gt;
&lt;p&gt;thanks&lt;br /&gt;
r&lt;/p&gt;
</description>
 <pubDate>Mon, 31 Dec 2007 09:32:18 -0800</pubDate>
 <dc:creator>randy</dc:creator>
 <guid isPermaLink="false">comment 3865 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>thanks for this!..can tell</title>
 <link>http://labs.echoditto.com/profile-module-form-wrapper#comment-3864</link>
 <description>&lt;p&gt;thanks for this!..can tell me how to implement this?  make a new module called mymodule.module?&lt;/p&gt;
&lt;p&gt;thanks!&lt;br /&gt;
r&lt;/p&gt;
</description>
 <pubDate>Mon, 31 Dec 2007 08:51:24 -0800</pubDate>
 <dc:creator>randy</dc:creator>
 <guid isPermaLink="false">comment 3864 at http://labs.echoditto.com</guid>
</item>
<item>
 <title>making profile.module appear in places it doesn&#039;t want to</title>
 <link>http://labs.echoditto.com/profile-module-form-wrapper</link>
 <description>&lt;p&gt;Out of all the modules in Drupal Core, Profile has always seemed me to be the most half-assed.  It&#039;s clear that something needs to happen to it &amp;mdash; using CCK field types at the least, maybe removing profile data from the user object, and, if I had my way, permanently node-ifying users.  I haven&#039;t poked around Drupal 6 as thoroughly as I ought to, but based upon what I&#039;ve heard from &lt;a href=&quot;http://labs.echoditto.com/node/37&quot;&gt;Phil&#039;s writeup&lt;/a&gt; and the &lt;a href=&quot;http://www.lullabot.com/audiocast/drupal_podcast_no_43_new_features_drupal_6&quot;&gt;Lullabot podcast&lt;/a&gt;, I may have to wait a bit longer to see meaningful change come to Profile.&lt;/p&gt;

&lt;p&gt;So others may find themselves in the situation I did yesterday for a bit longer: trying to embed a profile form somewhere that Profile.module doesn&#039;t think it ought to go &amp;mdash; for instance, yesterday I needed to let users edit their name and address on their user_profile page, rather than expecting them to mess around with a bunch of tabs and only-vaguely-different categories.&lt;/p&gt;

&lt;p&gt;You&#039;d &lt;em&gt;think&lt;/em&gt; there&#039;d be a way to call drupal_get_form() to collect your users&#039; addresses and names whereever you might care to.  But you&#039;d be wrong, so far as I can tell &amp;mdash; profile.module acts as a user.module parasite, accomplishing what it does through hook_user() and the abuse of arg().&lt;/p&gt;

&lt;p&gt;But it&#039;s very easy to re-wrap Profile&#039;s form-generating functions in your own module and then call drupal_get_form() against it.  Here&#039;s the example that I came up with:&lt;/p&gt;

&lt;blockquote&gt;&lt;pre&gt;
/* 
WRAPPER FUNCTIONS FOR PROFILE.MODULE FORM 

The profile form is usually only available on the user editing form.
Some wrapper functions are necessary to make it work elsewhere.
*/
function mymodule_profile_form($user,$category)
{
	if(module_exists(&#039;profile&#039;))
	{
		$user = user_load(array(&#039;uid&#039; =&gt; $user-&gt;uid));
	
		$edit = array();
		foreach($user as $key =&gt; $value)

			if(preg_match(&#039;/^profile_/&#039;,$key))
				$edit[$key] = $value;		
		
		$form = profile_form_profile($edit, $user, $category);
				
		// now let&#039;s pretend we&#039;re in hook_form_alter							
		
		// add a submit button
		$form[&#039;op&#039;] = array
		(
			&#039;#type&#039; =&gt; &#039;submit&#039;,
			&#039;#value&#039; =&gt; t(&#039;Submit&#039;),
		);
		
		// pass along the $category parameter as a hidden value
		$form[&#039;category&#039;] = array
		(
			&#039;#type&#039; =&gt; &#039;hidden&#039;,
			&#039;#value&#039; =&gt; $category,
		);
		
		return $form;
	}
}

function mymodule_profile_form_validate($form_id,$form_values)
{
	if(module_exists(&#039;profile&#039;))
	{
		/* do any necessary custom validation here */ 
		
		return profile_validate_profile($form_values, $form_values[&#039;category&#039;]);	
	}
}

function mymodule_profile_form_submit($form_id,$form_values)
{	
	global $user;
	if(module_exists(&#039;profile&#039;))
	{
		$r = profile_save_profile($form_values, $user, $form_values[&#039;category&#039;]);

		// reload the user with the newly-saved info
		$user = user_load(array(&#039;uid&#039; =&gt; $user-&gt;uid));

		return $r;
	}
}
&lt;/pre&gt;&lt;/blockquote&gt;

&lt;p&gt;You can call all of this with a simple drupal_get_form(&#039;mymodule_profile_form&#039;,&#039;Personal Information&#039;) &amp;mdash; if &quot;Personal Information&quot; is the profile category that you wish to get a form for.&lt;/p&gt;

&lt;p&gt;Of course, what&#039;d be &lt;strong&gt;really&lt;/strong&gt; nice is for profile.module to provide wrapper functions like this natively.  Maybe there&#039;s another way to skin this cat, but at the moment I think this is the option that users are facing.&lt;/p&gt;</description>
 <comments>http://labs.echoditto.com/profile-module-form-wrapper#comments</comments>
 <category domain="http://labs.echoditto.com/taxonomy/term/46">drupal</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/57">drupal5</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/93">formsapi</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/95">profile</category>
 <category domain="http://labs.echoditto.com/taxonomy/term/94">profilemodule</category>
 <pubDate>Thu, 20 Sep 2007 07:24:41 -0700</pubDate>
 <dc:creator>Tom</dc:creator>
 <guid isPermaLink="false">44 at http://labs.echoditto.com</guid>
</item>
</channel>
</rss>
