$_POST value problem

Started by SNewman, January 22, 2009, 11:09:16 AM

Previous topic - Next topic

SNewman

Ok so here is my situation.  I'm running SMF 2.0 Beta 4, and I have a number of custom fields configured for registration.  What I'm trying to do is modify the registration process so that the newly registered user is assigned a specific membergroup based upon their selection in the custom field.  In a previous attempt to seek help from the community, I was instructed to try using $_POST to get the value of the custom field.  However, when I do so, I get some other value which is not at all what I wanted.

File: Sources/Subs-Members.php
// Register them into the database.
$smcFunc['db_insert']('',
'{db_prefix}members',
$column_names,
$values,
array('id_member')
);
$memberID = $smcFunc['db_insert_id']('{db_prefix}members', 'id_member');

        $varX = $_POST['customfield[status]'];
        echo $varX;


Yields:

display_quick_reply = 1

The registration page: http://www.psplockhaven.org/register (Feel free to register a test account.  I've registered a million already trying to fix this)

I have been working on this problem for quite some time now and I would really like to finally resolve it.  Any help would be greatly appreciated.  Thanks in advance :)

Dragooon

It seems to be correct. As it says in HTML
<option value="1" >Prospective Member</option>
So the value passed in POST would be "1" not "Prospective Member". This is how SMF processes the option's array.

SNewman

Ah I see.  I don't know what the display_quick_reply is about either but I guess it's just another SMF thing.  My next question would be how I go about assigning the member group.  This is the code I have so far:

       $smcFunc['db_query']('', '
UPDATE {db_prefix}members
SET id_group = {int:memGroup}
WHERE id_member IN ({int:min_posts})',
array(
'memGroup' => $_POST['varX'],
'min_posts' => $memberID,
)
);

Dragooon

I'd suggest it this way...
$group_ids = array(
      1 => #
      2 => #
      3 => #
);
// Just a check
if (isset($group_ids[$varX]))
$smcFunc['db_query']('', '
      UPDATE {db_prefix}members
      SET id_group = {int:new_group}
      WHERE id_member = {int:member}',
      array(
            'new_group' => $group_ids[$varX],
            'member' => $memberID
      )
);

The $group_ids array is a simple array containing the IDs of the group to change according to the value of $_POST(Since you definitely won't like them to be an admin if they select an option of value "1" right?). Its basically post_value => new_group_id.

SNewman

Now I'm getting:

The database value you're trying to insert does not exist: new_group

Dragooon

Did you set the values and are they valid? Can you paste the code you're using?

SNewman

$group_ids = array(
      1 => "9",
      2 => "10",
      3 => "11",
      4 => "12"
);
$smcFunc['db_query']('', '
      UPDATE {db_prefix}members
      SET id_group = {int:new_group}
      WHERE id_member = {int:member}',
      array(
            'new_group' => $group_ids[$varX],
            'member' => $memberID
      )
);

Dragooon

Are you actually defining $varX?

SNewman

Yes.

        $varX = $_POST['customfield[status]'];

$group_ids = array(
      1 => "9",
      2 => "10",
      3 => "11",
      4 => "12"
);
$smcFunc['db_query']('', '
      UPDATE {db_prefix}members
      SET id_group = {int:new_group}
      WHERE id_member = {int:member}',
      array(
            'new_group' => $group_ids[$varX],
            'member' => $memberID
      )
);

[SiNaN]

It should be $_POST['customfield']['status'].
Former SMF Core Developer | My Mods | SimplePortal

SNewman

Thank you so much!  It finally works!  Ahhh thank you!

Dragooon


pkrpkr

Quote from: [SiNaN] on January 22, 2009, 02:04:40 PM
It should be $_POST['customfield']['status'].
Thanks from me too! - finally learned the right syntax to lookup a custom field after hours of trial and error.

Advertisement: