Creating online form with fields filled up with membership details

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #137101 by bumble
Hi Tuan, I am unable to pull the information from a custom field. It is not in the #__osmembership_subscribers table. Where can I find it? How should I code it?

Guessing it has something to do with field id from #__osmembership_field_value table? Correct me if I'm wrong! Waiting for your reply. Thank you!

Please Log in or Create an account to join the conversation.

More
3 years 8 months ago #137102 by Tuan Pham Ngoc
You're right that you will have to query data directly from #__osmembership_field_value table

Tuan

Please Log in or Create an account to join the conversation.

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #137103 by bumble
Ok so I now have to pull a custom field from another table:
#__osmembership_field_value table
The fields have field IDs and not names.
Can you advise how I should add this to the existing code?
Thank you.

Please Log in or Create an account to join the conversation.

More
3 years 8 months ago #137105 by Tuan Pham Ngoc
What code you are using to get data now?

Please Log in or Create an account to join the conversation.

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #137106 by bumble
Here is the code:
$this->execPieceByName('ff_InitLib');
$db = JFactory::getDbo();
$db->setQuery("Select * From #__osmembership_subscribers Where user_id = " . $db->quote(JFactory::getUser()->get('id')));
$subscriber = $db->loadObject();

ff_setValue('last_name', $subscriber->last_name);
ff_setValue('first_name', $subscriber->first_name);
ff_setValue('membership_id', $subscriber->membership_id);

Please Log in or Create an account to join the conversation.

More
3 years 8 months ago #137107 by Tuan Pham Ngoc
Try this code:
Code:
$db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('a.name, b.field_value') ->from('#__osmembership_fields AS a') ->innerJoin('#__osmembership_field_value AS b ON a.id = b.field_id') ->where('b.subscriber_id = ' . $subscriber->id); $db->setQuery($query); $fieldValues = $db->loadObjectList('name'); if (isset($fieldValues['test_field_1'])) { $testField1Value = $fieldValues['test_field_1']->field_value; } else { $testField1Value = ''; } if (isset($fieldValues['test_field_2'])) { $testField2Value = $fieldValues['test_field_2']->field_value; } else { $testField2Value = ''; }

Try that code. it allows you to get value of custom field with name test_field_1, test_field_2. Hope you get the logic and can make it works as you want

Tuan

Please Log in or Create an account to join the conversation.

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #137125 by bumble
Hi Tuan,
Can't seem to get it to work.
Do we need to reference #__osmembership_fields table to get the name of the field?
Or is "test_field_1" is field ID?

Please Log in or Create an account to join the conversation.

More
3 years 8 months ago #137148 by Tuan Pham Ngoc
test_field_1, test_field_2 is name of the custom field. Could you paste the actual code you are using so that I can look at it to see what's wrong?

Tuan

Please Log in or Create an account to join the conversation.

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago #137170 by bumble
I wish to display these 4 fields in a Crosstec BreezingForms fields:
1. First Name: "first_name"
2. Last Name: "last_name"
3. Membership ID: "membership_id"
4. Identification Number: "idnumber"

The first 3 fields load fine with the original code.
Having problems with the 4th field as it is a custom field and must be pulled from other tables.

How do I combine the previous code with the new code?
When I add the code below the form does not load & page only displays the word Error.

Please Log in or Create an account to join the conversation.

  • bumble
  • Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
3 years 8 months ago - 3 years 8 months ago #137171 by bumble
Could not upload the code as it kept bringing this up: "SQL injection was detected and blocked."
So uploaded an image.
Attachments:
Last edit: 3 years 8 months ago by bumble.

Please Log in or Create an account to join the conversation.