Jump to content
  • 0
fossxplorer

Custom service option text field in a module

Question

Sorry since i'm cross posting, but i might have posted my question in wrong place. Moderators, feel free to delete one of them.

But i really need help to figure out how i can add a service option text field to grab a username for a module i've created. It's very simple module, straight from examples https://docs.blesta.com/display/dev/Module+Methods

In WHMCS it was very easy for me to do so. And i don't any flexibility to add from Manage module like with Universal Module, but just a simple text field and read that service option field to provision users.

 

Thanks :)

Share this post


Link to post
Share on other sites

4 answers to this question

Recommended Posts

  • 0
On 6/17/2017 at 8:41 AM, fossxplorer said:

Sorry since i'm cross posting, but i might have posted my question in wrong place. Moderators, feel free to delete one of them.

But i really need help to figure out how i can add a service option text field to grab a username for a module i've created. It's very simple module, straight from examples https://docs.blesta.com/display/dev/Module+Methods

In WHMCS it was very easy for me to do so. And i don't any flexibility to add from Manage module like with Universal Module, but just a simple text field and read that service option field to provision users.

 

Thanks :)

I do not fully understand your question. Let me try and say it back to you:

You created a custom module with Blesta in PHP. You would like during the order process for someone to enter a custom field called username (which is not the same and 100% different username of the person logged into Blesta) and you grab that input?

Have you looked at ModuleFields? https://docs.blesta.com/display/dev/ModuleFields

 

The other way to do this, is use the Universal Module, add a custom field to the order process. The Universal Module has a very useful option to make external ReST calls when an order is submitted. You would listen for this ReST call and then put all your business logic in that call.

Blesta Admin -> Modules -> Managed Universal Module -> Edit Product Label (create a product label if you have not already)

rest-calls.png.d41f1e6c91c11fb2ea84399656da20ee.png

-Adam

 

Share this post


Link to post
Share on other sites
  • 0
3 hours ago, Adam said:

I do not fully understand your question. Let me try and say it back to you:

You created a custom module with Blesta in PHP. You would like during the order process for someone to enter a custom field called username (which is not the same and 100% different username of the person logged into Blesta) and you grab that input?

Yep, you got it correct :)

3 hours ago, Adam said:

Have you looked at ModuleFields? https://docs.blesta.com/display/dev/ModuleFields

 

The other way to do this, is use the Universal Module, add a custom field to the order process. The Universal Module has a very useful option to make external ReST calls when an order is submitted. You would listen for this ReST call and then put all your business logic in that call.

Blesta Admin -> Modules -> Managed Universal Module -> Edit Product Label (create a product label if you have not already)

rest-calls.png.d41f1e6c91c11fb2ea84399656da20ee.png

-Adam

 

No, i didn't read docs related to ModuleFields. I will take a closer look at it, thanks!

I've been "cloning" cPanel as well as Universal module. And i think, for a Blesta newbie like me, the Universal module looks simpler for me to start with. I've been able to create a custom text field for now. And yes, would be nice if i'm able to  POST to a URL, but my API call looks like the following:

POST http://admin:secret@example.com/ocs/v1.php/cloud/users -d userid="username" -d password="fpassword"

Is it possible to POST to such a URL with some options? For the password,i'm planning to use Blesta's password (is it wiser to add a custom password field perhaps) and how do i grab the user's Blesta password? I got the welcome dump variables, and i see no password there. 

Thanks a lot for your reply @adam !

 

 

Blesta_002.png

Share this post


Link to post
Share on other sites
  • 0
On 18/06/2017 at 9:38 PM, fossxplorer said:

Yep, you got it correct :)

No, i didn't read docs related to ModuleFields. I will take a closer look at it, thanks!

I've been "cloning" cPanel as well as Universal module. And i think, for a Blesta newbie like me, the Universal module looks simpler for me to start with. I've been able to create a custom text field for now. And yes, would be nice if i'm able to  POST to a URL, but my API call looks like the following:

POST http://admin:secret@example.com/ocs/v1.php/cloud/users -d userid="username" -d password="fpassword"

Is it possible to POST to such a URL with some options? For the password,i'm planning to use Blesta's password (is it wiser to add a custom password field perhaps) and how do i grab the user's Blesta password? I got the welcome dump variables, and i see no password there. 

Thanks a lot for your reply @adam !

 

in your module file, you will find the fucntion

    public function getClientAddFields($package, $vars = null)

add the fallowing code

        $user_name = $fields->label('Enter Username', 'username');
        $user_name->attach(
            $fields->fieldText(
                'username',
                $this->Html->ifSet($vars->username),
                ['id' => 'username']
            )
        );
        // Set the label as a field
        $fields->setField($user_name);

for blesta password, you can't get the password, if you can got it, then you can send a exploit CVS to blesta :)

Share this post


Link to post
Share on other sites
  • 0

I added that code into getClientAddFields() and got: Undefined variable: fields.

But now that i'm using universal module (cloned), i've been easily able to create custom fields.

So my questions are:

1. how do i access the custom fields in my code?

2. How do i POST using some options like -d "username" -d "password"?

3. The external system requires an additional header be sent with the POST request (-H "header: value" like:

POST http://admin:secret@example.com/ocs/v1.php/cloud/users -d userid="username" -d password="fpassword"  -H "OCS-APIRequest: true"

Is this also achievable with universal module?

 

Also, the external system requires me to not only POST, but also GET and PUT, DELETE etc.

To start with, i need both API calls of POST and PUT in order to provision users. Is this supported by the universal module (i've cloned this module and named it mymodule).

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×