Recent Topics

1 Oct 03, 2011 15:33    

[4.x]

I'm gradually moving forward on my plugin - slow as I seem to be having to re-learn a new language

Basically the plugin is a form with a drop down list of options. Each option contains a url back into b2evo generated through get_permanent_url() and an a separate text field.

Where in the Plugin should I act on these POSTed field values?

It obviously needs to be before any site headers are sent to allow the redirect. I though in the _create() for the plugin but where is this code normally placed?

2 Oct 05, 2011 21:58

You need to post your form to /htsrv/call_plugin.php

Example:

function GetHtsrvMethods()
{
	return array( 'whatever' );
}


function htsrv_whatever( $params = array() )
{
	// Use param() to get posted fields
	$field_value1 = param( 'field_1', 'integer' );
        $field_value2 = param( 'field_2', 'string' );
        $field_value3 = param( 'field_3', 'text' );
        $field_value4 = param( 'field_4', 'html' );

    // There's also a chance that you can access form values from $params, I don't remember :)
      var_export($params);
}


function display_form()
{
    echo '<form action="'.$this->get_htsrv_url('whatever').'" method="post">
        <input name="field_1" value="9" />
        <input name="field_2" value="http://www.com" />
        <input name="field_3" value="multi-line
text" />
        <input name="field_4" value="multi-line
<b>HTML</b>
text" />
</form>';
}

3 Oct 06, 2011 10:45

Not sure I follow how that works :(

For now I have simply added the following to the plugin's constructor:


		# check for _POST'ed value and do a redirect
		$this->cb_name = 'cat_url';
		$cat_url = param($this->cb_name, 'string');
		if (isset($cat_url) && !empty($cat_url)) header_redirect($cat_url);

It appears to work and has the advantage of keeping the code within the plugin.

I should add that this needs only to work on blogs that contain the plugin (ie the cat_url is not only sent from such a blog/page but is itself an url to a blog/page containing the plugin)

4 Oct 06, 2011 11:22

How do you display/post the form?

5 Oct 06, 2011 12:36

Simple hard code output inside the plugin SkinTag()
The <form ... is output along with the <select ... <options

This was simpler than digging around to find any pre-defined (unclearly documented) function in the core.

The form contains a dropdown list of categories that are made available based on certain conditions.

It just seemed easier that way, keeping it in the new plugin.

But always welcome any suggestions if there is a more universal way of doing something ... as long as it does what is required of it.

6 Oct 06, 2011 20:33

Simple hard code output inside the plugin SkinTag()
That's the right way :) Then just replace your form "action" URL with the one I posted above, and add two methods "GetHtsrvMethods" and "htsrv_whatever" to your plugin.

Never try to grab from input on plugin init, this is a huge overhead!

Once you setup your form to post data to /htsrv/call_plugin.php file you'll be able to grab submitted values with "htsrv_whatever". Dynamic action URL is generated by "$this->get_htsrv_url('whatever')"

7 Oct 06, 2011 23:14

I don't see how there is any significant overhead in the constructor it is only called once on any client request and pulling the POSTed value using the param method is not going to be much different from any other solution - if it is then I could simply get the raw POSTed value and drop ot in a private class var and use that.

Doing it the way I have done it doesn't even require the overhead of loading the $Form class or any of the htsrv_whatever methods. As I said really simple and probably not PC

Still god to know there is an alternate way of doing things and when I have more time I will delve into htsrv_whatever and see what it does.
At the moment I don't understand it.


Form is loading...