Jump to content

Input field with AJAX


Recommended Posts

I'm looking to do a specific type of module. I want to use the field-typemulti fieldtype. So what I want to accomplish is
the first field part stores a category (movies, books, etc.). The Second input field would need to be an AJAX lookup that would let me choose the ID of that book so I can take it and save it into my post. So let's just say the thing I'm pulling from is IMDB, I'll choose the movie category, then On the lookup get a list of movies based on a search. IF you can point me and help me out with this i'd greatly appreciate it!

Link to comment
Share on other sites

No need for a extra Process page. Just send a ajax POST/GET request with a special key you recognize in your module's init(), do the work and send back an result.

  • Like 3
Link to comment
Share on other sites

  • 2 weeks later...
On 07/07/2016 at 5:09 PM, Soma said:

No need for a extra Process page. Just send a ajax POST/GET request with a special key you recognize in your module's init(), do the work and send back an result.

Hi @Soma. Could you please elaborate on how to do this? I don't quite follow what is being sent where :). Thanks..

Link to comment
Share on other sites

Something along the way

public function init(){
	if($this->config->ajax && $this->input->InputfieldMyAjaxBomb){
		// handle your ajax request
		header('Content-Type: application/json');
		echo "{'yo':'yo'}";
		exit;
	}
}

.. in your Inputfield init(). Then you can make a post or get AJAX request to any backend or public url the current url containing the key InputfieldMyAjaxBomb=1.

Edit: Originally I didn't really mean that there's "no need". Well, of course a hidden admin ProcessPage bundled with your module is also good and honestly maybe even the more correct way. But It's easy to implement and test things out too.

  • Like 1
Link to comment
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
 Share

×
×
  • Create New...