Edit Profile Quirk

By Rusty - December 17, 2010

Using the membership plugin I noticed a quirk, with a pretty simple workaround.

On the sample_profile.php page provided with the plugin, from lines 6->10 is the following code:

// prepopulate form with current user values
foreach ($CURRENT_USER as $name => $value) {
if (array_key_exists($name, $_REQUEST)) { continue; }
$_REQUEST[$name] = $value;
}


It works great, and does what it needs, but that's when it's on its own.

Once I tried to integrate that within another page that utilizes includes, and calls up other tables (for a header image, left column, right column & footer elements etc) I noticed that they were breaking. I was getting a Notice: Undefined Index and all other sorts of witchcraft. (not a typo :D)

So, with a wee bit of systematic elimination I was able to deduce that the above code was causing the issue.

My fix to this problem, though not glorious, could perhaps save some other poor soul more than a few precious moments from their life...

I placed all the PHP that is specifically related to the form, including the following juice bits.
// prepopulate form with current user values
// process form
// error checking
// new password checking
// check for duplicate usernames and emails
// update user
// on success
// delete account
// delete uploads
// delete account
// redirect to login


ALL of that I placed at the VERY VERY bottom of my PHP page, immedately before my closing </body> & </html> tags, I made sure to even put it after:

<?php if (!$home_pageRecord): ?>
No record found!<br/><br/>
<?php endif ?>


Perhaps someone will chime in with a way to re-write, or re-configure/structure the PHP call functions to get them to not break, but for now I'm just glad to have figured out what was breaking my includes/calls from other tables.
Rusty

Re: [Rusty] Edit Profile Quirk

By Jason - December 17, 2010

Hi Rusty,

That's an interesting problem. Was the "Undefined Index" warnings coming from sample_profile.php or from your included files? Was it stopping the other files from returning records?

My first thought would be that the other included files are not using
'allowSearch' => false,

Which means they'll be looking for variables inside the $_REQUEST array to perform a search with. The code you reference will insert the variable "num" into the $_REQUEST array which is a unique record number for any given section. This is probably what was throwing everything else off.

You could add this to the code:

// prepopulate form with current user values
foreach ($CURRENT_USER as $name => $value) {
if (array_key_exists($name, $_REQUEST) || $name=="num") { continue; }
$_REQUEST[$name] = $value;
}


This will stop "num" from getting into the $_REQUEST array.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] Edit Profile Quirk

By Rusty - December 17, 2010 - edited: December 17, 2010

Ahh, I see exactly what you're saying there. You are correct yet again! And yes indeed the errors were coming from my pages/table calls, NOT from within the form itself.

I'll do some further comparison / sandboxing this weekend to try figure out why or what it is unique about this configuration of code structure/sequence/ordering.

I am aware that at this point, I'm more or less like a bull (with an elevated IQ) in a china shop in relation to me & the CMS Builder code - and I'm not saying that CMSB is fragile, just that I can screw up anything. But then again, I usually break things in the process of figuring them out [angelic]
Rusty