Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:21:27+00:00 2026-06-18T02:21:27+00:00

I am trying to display different forms based on user type using Ajax post

  • 0

I am trying to display different forms based on user type using Ajax post request. The request response works fine but I don’t know how to display the form. For example, if the user selects parent then I want the parent form to be displayed and so on. I’m using ZF 1.12.

public function init() {
    $contextSwitch = $this->_helper->getHelper('AjaxContext');
    $contextSwitch =$this->_helper->contextSwitch();
    $contextSwitch->addActionContext('index', 'json')
    ->setAutoJsonSerialization(false)
    ->initContext();
}

public function indexAction() {
    $this->view->user = $this->_userModel->loadUser($userId);
    //if($this->_request->isXmlHttpRequest()) {
        //$this->_helper->layout->disableLayout();
        //$this->_helper->viewRenderer->setNoRender(true);
    if ($this->getRequest()->isPost()){
        $type = $_POST['type'];
        $this->view->userForm = $this->getUserForm($type)->populate(
            $this->view->user
        );
    }
}

And here’s what I have on the client side. What do I need to write in the success section?

<script type="text/javascript"> 
  $(document).ready(function(){
    $('#userType').on('change', function(){
      var type = $(this).val();
      select(type);
    });
  });

  function select(type) {
    $.ajax({
        type: "POST",
        url: "admin/index/",
        //Context: document.body,
        data: {'type':type},
        data: 'format=json',
        //dataType: "html",
        success: function(data){
         // what to do here?
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {}
    });
}
</script>
<form id="type" name="type" method="post" action="admin/index">
  <select name='userType' id='userType' size='30'>
    <option>admin</option>
    <option>parent</option>
    <option>teacher</option>
  </select>
</form>
<div id="show">
  <?php //echo $this->userForm;?>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:21:28+00:00Added an answer on June 18, 2026 at 2:21 am

    If your ajax request form returns you the HTML from the Zend_Form, you could simply write the HTML in the #show div.

    In you view you will need to do this :

    echo $this->userForm;
    

    This way, all the required HTML will be written on the server side, before sending the response to the HTML page. In the HTML page you then just have to write the response in the right location with the method $('#show').html(data). You also have to make sure that each of your forms has the right action when you render them.

    The other option would be to have all three forms hidden in your page (through Javascript) upon loading and based on the select (Generated with JS), display the right form. This way you don’t have to load data from an external source and if someone have JS disabled, he still can use the application. On the other hand, this method will have each page load about 1/2 a KB more of data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display a notification using Easy Notification , but I don't want
I'm trying to display a page in NSIS to obtain two different values. I
I'm trying to use the show and hide to display a different set of
Trying to display current time with PHP (using this ): $date = date('m/d/Y h:i:s
Im trying to display some files in a web page so the user can
I am trying to display my popover menu whenever the user clicks on a
i'm trying to make a small project that uses multiple forms (dialogs) for different
I'm using Python and Flask to display a randomized game board, and trying to
I'm using forms authentication to log users onto my website. But what happens if
I have some data that I am trying to display using the Google Visualization

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.