Solved

Ajax modal form with select2

Posted on 2016-09-15
5
64 Views
Last Modified: 2016-09-25
Hi,

I'm using Select2 on all regular form PHP page and this is working ok.

I need to add a select2 field to an existing ajax form which is a modal php form.
I don't have much experience with Ajax so I'm not sure which value to use to replace adduser-user_division_id into the select
usually I use a variable but I don't what to do with this one
The result give me empty list
error: Notice: Undefined index: division_id

The same modal used to add / edit the infos

Let me know if you need other info.


Form part
<div class="form-group">
	<label class="control-label col-md-3" for="adduser-user_division_id">
		<?php echo ASLang::get('division'); ?><span class="required">*</span>
	</label>							
	<div class="controls col-md-9">
		<?php $divisions = $db->select("SELECT * FROM `as_division`"); ?>
			<select id="adduser-user_division_id" name="adduser-user_division_id" class="form-control select2-single select2-hidden-accessible input-sm" tabindex="-1" aria-hidden="true">
				<?php foreach($divisions as $division): ?>
					<option></option>
						<?php
							echo '<option value="' . $division["division_id"] . '"' .
							(( adduser-user_division_id ==  $division["division_id"]) ? ' selected' : '') . '>' .
							 $division["division_name"] .   '</option>';
						?>
					<?php endforeach; ?>									
			</select>	
	</div>
</div>

Open in new window

0
Comment
Question by:lenamtl
  • 3
5 Comments
 
LVL 55

Assisted Solution

by:Julian Hansen
Julian Hansen earned 250 total points
ID: 41800408
What is a select2? I am assuming it is this https://select2.github.io/ ?

Where is the AJAX form
How is it invoked
Where is the JavaScript / JQuery that invokes the form.

It is difficult to see from the snippet you have posted what the full picture is. The more info you can provide the easier it will be for us to get on top of what it is you are trying to do.
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 250 total points
ID: 41800722
this adduser-user_division_id must be a parameter sent during the ajax call
if the ajax call use GET method, you gonna be able to get it (again, if you send it as ajax parameter) :

So your line 12 :
(( $_GET["adduser-user_division_id"] ==  $division["division_id"]) ? ' selected' : '') . '>' .

Open in new window

0
 
LVL 25

Author Comment

by:lenamtl
ID: 41801538
It's look like as the form get dynamically filed by js this will require some extra js and php adjustment otherwise it won't work.
I may decide to rewrite the form to a non popup page as there will have more field to add

I will do some test and the weekend and get back with more info.
0
 
LVL 25

Accepted Solution

by:
lenamtl earned 0 total points
ID: 41806572
I decide to change modal from for page form and I'm not using the same form for adding and editing.
0
 
LVL 25

Author Closing Comment

by:lenamtl
ID: 41814573
I have found another method to fix the problem
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question