John Zumbrum
John Zumbrum

Reputation: 2856

Yii: Dynamically load new model with ajax

I'd like to have a section with two dropdowns which effectively dictate which model to use. I would like this to have a button with an onclick property that essentially clears the form, and replaces it with a new form, based on the new model.

Is there a way to do this in Yii, or perhaps a better way to achieve this functionality?

Upvotes: 2

Views: 674

Answers (1)

Fydo
Fydo

Reputation: 1424

You can do this with or without ajax.

With AJAX:

  1. Render your view with a single form model and the form's options selected accordingly.
  2. Create a new action that will respond with a json string encoding of the appropriate form based on the post param the action receives.
  3. In the submit button click event handler, post to your new action which form you would like to receive.
  4. In the post callback, swap out the form with the new one you just received in your response.

Without AJAX:

  1. Render all the form models to the view.
  2. Have the submit button event handler display and hide the forms accordingly.

Upvotes: 1

Related Questions