Ajax help

cookn22

Active Member
I've been trying to figure out how to use Ajax based on what's provided in user_ajax_example.php but I'm not having much luck. I successfully got the provided example to work, so I know I have everything set up correctly. Honestly, all this ajax stuff is greek to me...What I'm trying to do is have a button in a form that updates the value of a field with a value in a database table when its clicked. The idea is to ask the user of the form whether they want previously entered form values copied over into the fields.

Here's the form:

Code:
<?php $group = $this->groups['update_placement - [joined to Client Update]']; ?>
	<h3>
	<a name="<?php echo $group->title;?>"><?php echo $group->title;?></a>
	</h3>
	<div class="fb_group" id="group<?php echo $group->id;?>" style="<?php echo $group->css;?>">
	<h2><?php echo "Last Updated: " . $placement_last_update;?></h2>
	<b><?php echo "Date: " . $placement_current_date;?>
	<br>
	<b><?php echo "Level: " . $placement_current_type;?></b>
		<?php foreach( $group->elements as $element ){?>
				<div class="fb_element" id="fb_element_<?php echo $element->int;?>"><?php if($element->error != ''){?>
				<div class="fabrikerror"><?php echo $element->error;?></div>
				<?php }?> <?php echo $element->label;?> <?php echo $element->element;?>
				</div>
			<?php }?>
			<br>
			<input type="button" name="fillplacefields" value "fill" onclick="InserFields()">
		</div>

And...that's as far as I've gotten. I'm kind of lost as to how to do this.
 
oops, meant to post this in General Usage..

I don't have anything that works yet, because I have no idea what I'm doing, but this is my closest guess as to what it might look like.

For the JS:

Code:
<script type="text/javascript">
 function InsertFields(update_id) {
 	 var url = "index2.php?option=com_fabrik&no_html=1&task=userPluginAjax&method=InsertFields&id=" + update_id;
 	 new Ajax(url, {
 		method: 'get',
 		update: $('join___20___update_placement___placement_date')
 	 }).request();
 }
 </script>

and the php code would look maybe like this:

Code:
function InsertFields()
	{
		$dbhost = "localhost";
		$dbuser = "";
		$dbpassword = "";
		$dbdatabase = "";
		$db = new database( $dbhost, $dbuser, $dbpassword, $dbdatabase);
		$id = mosGetParam($_REQUEST, 'update_id', '');
		$query = "SELECT placement_date FROM update_placement WHERE update_placement.update_id = '$id'";
		$db->setQuery( $query );
		$result = $db->query($query); if($db->getErrorNum()){echo $db->stderr();}
		$array = mysql_fetch_array($result);
		echo $array[0];	
}

Also I think I'll probably use a fabrik-made button instead of putting the code in the custom template.
 
hi Nathan

would you mind posting your solution, so that others that get to this thread see what the final outcome was.
at a guess I think you should have replaced all the $db stuff with a simple "global $db;" declaration, which would allow you to access Joomlas database

rob
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top