How to add an image icon to an Elgg entity - php

Elgg Version 2.0
How can I go about creating an Elgg entity with an image icon, just like how one can do when creating an Elgg group?
I've tried implementing the following, but no image gets uploaded:
Action file:
<?php
// get the form inputs
$title = get_input('title');
$body = get_input('body');
$tags = string_to_tag_array(get_input('tags'));
// create a new my_blog object
$blog = new ElggObject();
$blog->subtype = "nganya";
$blog->title = $title;
$blog->description = $body;
// for now make all my_blog posts public
$blog->access_id = ACCESS_PUBLIC;
// owner is logged in user
$blog->owner_guid = elgg_get_logged_in_user_guid();
// save tags as metadata
$blog->tags = $tags;
// save to database and get id of the new my_blog
$blog_guid = $blog->save();
// if the my_blog was saved, we want to display the new post
// otherwise, we want to register an error and forward back to the form
if ($blog_guid) {
system_message("Your nganya post was saved >>>>>>>>>> " . $blog_guid);
forward($blog->getURL());
} else {
register_error("The nganya post could not be saved");
forward(REFERER); // REFERER is a global variable that defines the previous page
}
$has_uploaded_icon = (!empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/'));
if ($has_uploaded_icon) {
$icon_sizes = elgg_get_config('icon_sizes');
$prefix = "nganya/" . $blog->guid;
$filehandler = new ElggFile();
$filehandler->owner_guid = $blog_guid;
$filehandler->setFilename($prefix . ".jpg");
$filehandler->open("write");
$filehandler->write(get_uploaded_file('icon'));
$filehandler->close();
$filename = $filehandler->getFilenameOnFilestore();
$sizes = array('tiny', 'small', 'medium', 'large', 'master');
$thumbs = array();
foreach ($sizes as $size) {
$thumbs[$size] = get_resized_image_from_existing_file(
$filename,
$icon_sizes[$size]['w'],
$icon_sizes[$size]['h'],
$icon_sizes[$size]['square']
);
}
if ($thumbs['tiny']) { // just checking if resize successful
$thumb = new ElggFile();
$thumb->owner_guid = $blog->owner_guid;
$thumb->setMimeType('image/jpeg');
foreach ($sizes as $size) {
$thumb->setFilename("{$prefix}{$size}.jpg");
$thumb->open("write");
$thumb->write($thumbs[$size]);
$thumb->close();
}
$blog->icontime = time();
}
}
The Form:
<div>
<label><?php echo elgg_echo("groups:icon"); ?></label><br />
<?php echo elgg_view("input/file", array("name" => "icon")); ?>
</div>
<div>
<label for="title"><?= elgg_echo("title"); ?></label><br />
<?= elgg_view('input/text', ['name' => 'title', 'id' => 'title']); ?>
</div>
<div>
<label for="body"><?= elgg_echo("body"); ?></label><br />
<?= elgg_view('input/longtext', ['name' => 'body', 'id' => 'body']); ?>
</div>
<div>
<label for="tags"><?= elgg_echo("tags"); ?></label><br />
<?= elgg_view('input/tags', ['name' => 'tags', 'id' => 'tags']); ?>
</div>
<div>
<?= elgg_view('input/submit', ['value' => elgg_echo('save')]); ?>
</div>

The action code looks correct. In Elgg 2.2, this will be a lot easier, but in the meantime:
You need to add a plugin hook handler for
'entity:icon:url',<entity_type> hook and replace the URL if
$params['entity'] is of the subtype your are adding
Update your page handler to serve a file for the above URL.

Related

How to Fix My Form Didn't Update Data to Database [Codeigniter]

I have a problem with my form. When i input the form and submit, the form didn't save to my database.
In my form showing code transaction, and email customer. And if customer buying product in my website.
I just confirmation the order with click form code transaction.
In form code transaction showing, code transaction and email customer. And me input the logistic name, no. order of logistic to customer tracking their order, and choice the order packet has sending.
But in my problem the form succes save the order packet information "has sending" , but for logistic name and no. order of logistic didn't save.
This is my view.
<div id="<?php echo $row['codetrans'] ?>" class="reveal-modal">
<h3>Detail Order</h3>
<?php echo form_open('order/edit_stats_order');
$codetrans = array(
'name' => 'codetrans',
'class' => 'column',
'size' => '30'
);
$email = array(
'name' => 'email',
'class' => 'column',
'size' => '30'
);
$no_order = array(
'name' => 'no_order',
'class' => 'column',
'size' => '30'
);
$log = array(
'FedEx' => 'FedEx',
'RPX' => 'RPX');
?>
<span>Code :</span>
<?php echo form_input($codetrans,$row['codetrans']) ?><br/>
<span>Email :</span>
<?php echo form_input($email,$row['email']) ?><br/>
<span>Logistic Name :</span><br/>
<?php echo form_dropdown('log', $log,$row['log']); ?><br/><br/>
<span>No. Order :</span>
<?php echo form_input($no_order,$row['no_order']) ?><br/>
<?php $options = array(
'0' => 'Not Sendirng',
'1' => 'Has Sending'); ?><br/>
<?php echo form_dropdown('stats_order', $options,$row['stats_order']); ?><br/>
<?php echo form_hidden('input_hidden_id',$row['codetrans']);?>
<?php echo form_submit('submit', 'Submit', 'class=searchbutton'); ?>
<?php echo form_close();?>
<a class="close-reveal-modal">×</a>
</div>
<?php
}
?>
</ul>
<?php echo anchor('order/stats_order', 'Open All Stats', 'class="btn btn_aS"' ); ?>
</div>
This my controller.
public function edit_stats_order() {
$this->load->model('Order_model');
$codetrans = $this->input->post('codetrans');
$email = $this->input->post('email');
$log = $this->input->post('log');
$no_order = $this->input->post('no_order');
$stats_order = $this->input->post('stats_order');
if($email !='' && $codetrans !='' && $log !='' && $no_order !=''){
$this->Order_model->edit_stats_order($codetrans,$email,$log,$no_order);
redirect('order/main');
}
else{
echo "<script>alert('Check Again!');</script>";
echo "<script>location.href = document.referrer</script>";
}
}
This is my model.
public function edit_stats_order($codetrans,$email,$log,$no_order){
date_default_timezone_set('xxxxx');
$data['email'] = $email;
$data['no_order'] = $no_order;
$data['log'] = $log;
$data['stats_order'] = $stats_order;
$data['date'] = date('Y-m-d');
$this->db->where('codetrans',$codetrans);
$this->db->update('ordering',$data);
}
Why the fault in my code?
Thanks
You are trying to use $stats_order in model function which is not defined in model. So you have to pass $stats_order to model function.
Add one more parameter to the function call for $stats_order in order to pass it to the model.
$this->Order_model->edit_stats_order($codetrans,$email,$log,$no_order,$stats_order);
Also add one more parameter in model function for the same. Change the first line of the function in model to,
public function edit_stats_order($codetrans,$email,$log,$no_order,$stats_order){

Creating zend form element array with same name (ZF3)?

Since i've to position checkboxes in design I'm not using MultiCheckbox and using Checkbox instead in zend. I've seen some zf1 solutions but didnt found any zf2 or zf3 solutions.
My Php Code
$languages = new \Zend\Form\Element\Checkbox('languages[]');
$languages->setLabel('English');
$languages->setValue('1');
This produce the following output
<?php
echo $this->formRow($form->get('languages[]'));
//It produce the following
?>
<input type="checkbox" name="languages[]" value="1" checked="checked">
How can I add more items with name "languages[]" without writing direct HTML code ?
You can use a Form collection for this:
1) In your form:
use Zend\Form\Element\Collection;
...
$languages = new \Zend\Form\Element\Checkbox();
$languages->setLabel('English');
$languages->setValue('1');
$languages->setName('language');
$collection = new Collection();
$collection->setName('languages');
$collection->setLabel('Language Collection');
$collection->setCount(2);
$collection->setTargetElement($languages);
$collection->populateValues(array(
1, 0
));
$this->add($collection);
2) Do not forget to prepare your form in your controller action:
$form->prepare();
3) Finally, in your view, get all elements of the collection and render them separately:
<?php $elements = $form->get('languages')->getElements(); ?>
<?php //echo $this->formCollection($form->get('languages')); ?>
<?php echo $this->formRow($elements[0]); ?>
<?php echo $this->formRow($elements[1]); ?>
You can use MultiChebox
https://framework.zend.com/manual/2.2/en/modules/zend.form.element.multicheckbox.html
It works similar to radio form element. Your example implementation
use Zend\Form\Element;
$languages = new Element\MultiCheckbox('languages');
$languages->setLabel('Used languages');
$languages->setValueOptions([
'en_US' => 'english',
'de_DE' => 'german',
'pl_PL' => 'polish',
]);
$languages->setValue('en_US'); //default value; you can use array
My solution (Method 2)
Method 1:
Give name as "language[1]" instead of "language[]". By using this I can call the elements in view seperately.
Creating form.
$language1 = new \Zend\Form\Element\Checkbox('language[1]');
$language2 = new \Zend\Form\Element\Checkbox('language[2]');
$form = new Form('Set');
$form->add($name)
->add($language1)
->add($language2)
->add($submit);
In view file
<div><?php echo $form->get('language[1]');?></div>
<div><?php echo $form->get('language[2]');?></div>
Edit: Method 2
Using fieldset
//Create form
$languages = [
['id' => 1, 'language' => 'English'],
['id' => 2, 'language' => 'Malayalam'],
] ;
$fieldSet = new \Zend\Form\Fieldset('languages') ;
foreach( $languages as $one ) {
$c = new \Zend\Form\Element\Checkbox($one['id']);
$c->setLabel($one['language']) ;
$fieldSet->add($c) ;
}
//Add collection of checkboxes to form
$form->add($fieldSet) ;
In view file
<?php
$language = $form->get('languages') ;
?>
<div class="form-group row">
<label class="control-label col-sm-2" >Choose Languages</label>
<div class="col-sm-10">
<?php foreach($language as $one ) { ?>
<?php echo $this->formCheckbox($one); ?> <span> <?php echo $this->formLabel( $one ) ; ?> </span>
<?php echo $this->formElementErrors($one); ?>
<?php } ?>
</div>
</div>

Wordpress theme fatal error "Fatal error: Call to undefined method WP_Error::get_items()"

One of my Wordpress themes is showing the following error:
Fatal error: Call to undefined method WP_Error::get_items() in /home1/mywebsite/public_html/learnphp123.com/wp-content/themes/econews/admin/IDE_admin.php on line 88
The code for the file is (you can see "get_items()" on line 88 .... actually the third line in the code):
if($feed) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
Can anybody tell me what to use in the place of "get_items()"?
Thank you very much for your help!
The total code of the file is given below and I am only getting the error on line 88 related to feed get_items ().
<?php
/*
Copyright 2010, idesigneco.com
http://idesigneco.com
*/
define('IDE_ADMIN_FEED', 'http://idesigneco.com/wp_pub.php?id=ide_admin_newsfeed.xml&theme='.IDE_CODE.'&ver='.IDE_VERSION);
// load form generator and validator
include IDE_ADMIN_PATH.'IDE_FormGenerator.class.php';
// initialize the admin form
$Form = new IDE_FormGenerator(array(
'name' => 'admin',
'method' => 'post',
'action' => ''
));
// setup the form fields
$Form->elements(
null,
array(
'admin_action' => array(
'type' => 'hidden', 'value' => 'admin',
'error' => 'Your settings have been updated.'
)
)
);
// load theme specific options
include IDE_ADMIN_PATH.'/IDE_admin_options.php';
$Form->elements(
null,
array(
'submit' => array(
'type' => 'submit', 'value' => 'Save', 'label' => ''
),
)
);
$Form->printErrors(true);
// ________________________________________________________
// process the form data
if(!empty($_POST['admin_action'])) {
// unchecked checkbox options don't show up, so fill them with predefined key names
ide_save_options( array_merge( array_fill_keys($IDE_checkboxes, ''),
stripslashes_deep($_POST)
)
);
$Form->setErrors(array('admin_action'));
}
// ________________________________________________________
// populate the form with saved options
$Form->data($IDE_options);
// ________________________________________________________
// print out the admin area
ide_admin_header();
$Form->generate();
ide_admin_footer();
// ________________________________________________________
// idesigneco news feed
function ide_admin_news() {
$time = ide_option('admin_newsfeed_time');
$html = ide_option('admin_newsfeed');
// feed expired, update
if(!$html || !$time || ($time+(5*3600)) < time() ) {
if(function_exists('fetch_feed')){
$feed = fetch_feed(IDE_ADMIN_FEED);
if($feed) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
$html.= '</ul>';
} else {
$html = 'Updates unavailable at this time';
}
} else {
// deprecated feed api
if(function_exists('fetch_rss')){
include_once(ABSPATH . WPINC . '/rss.php');
$rss = fetch_rss(IDE_ADMIN_FEED);
$html = '<ul>';
foreach ($rss->items as $item){
$html.="<li><span>".date('d M Y', strtotime($item['pubdate']))."</span> ".$item['title']."</li>";
}
$html.= '</ul>';
}
}
ide_save_option('admin_newsfeed_time', time());
ide_save_option('admin_newsfeed', $html);
}
echo $html;
}
// admin header
function ide_admin_header() {
?>
<div id="ide_admin">
<div class="left">
<h1 class="ide_title"><?php echo IDE_NAME.' '.IDE_VERSION; ?></h1>
<div class="clear"> </div>
<?php
}
// admin footer
function ide_admin_footer() {
?>
</div><!-- left //-->
<div class="right">
<div class="idesigneco">
<img src="<?php echo IDE_ADMIN_STATIC.'/idesigneco.png'; ?>" alt="Theme by iDesignEco" title="Theme by iDesignEco" />
</div>
<div class="news">
<h2>iDesignEco Updates</h2>
<?php ide_admin_news(); ?>
</div>
</div><!-- right //-->
<div class="clear"> </div>
</div><!-- ide_admin //-->
<?php
}
?>
This probably happens when getting data for $feed fails, so it becomes WP_Error class that does not have get_items() method. Try to modify the code like this:
if (! is_wp_error( $feed )) {
$html = '<ul>';
foreach ($feed->get_items() as $item){
$html.="<li><span>".$item->get_date('d M Y')."</span> ".$item->get_title()."</li>";
}
UPDATE:
Just as I assumed, the $feed gets its data from fetch_feed(), so the solution should still be to replace:
if($feed) {
with:
if (! is_wp_error( $feed )) {

I want to pause a while loop until user submit a form, so how can I do that?

I have a 25 advertiserids from CJ and now I want to create 2 post in different category of wordpress from each advertiserid given. So I have created following script but it is not pausing for user input, so how can I do that ?
If its not possible with while then is there any other method to do this ? in script $ad is array with advertiser's id value and $adcat is also a array with advertiser's catagory
function cjlinks($n)
{
global $ad, $adcat;
$URI = 'https://product-search.api.cj.com/v2/product-search?website-id=12345678'.
'&advertiser-ids='.$ad[$n].
'&records-per-page=2';
$context = stream_context_create(
array(
'http' => array(
'method' => 'GET',
'header' => 'Authorization: ' .
'my api id'
)
));
$res = new SimpleXMLElement(file_get_contents($URI, false, $context));
return $res;
}
$a = 0;
while ($a < 25)
{
echo 'advertiser id is: '.$ad[$a].'<br/>advertiser - catagory is: '.$adcat[$a]->child.
'<br/>';
if (isset($_SESSION['sumit'])){
$data = cjlinks($a);
$attributes = $data->products->attributes();
if ($attributes->{'total-matched'} == 0){
echo 'No products found ...try again with new keyword.';
}else{
foreach ($data->products[0] as $product)
{
// Sanitize data.
$price = number_format((float)$product->price, 2, '.', ' ');
$image = '<img src="'.$product->{'image-url'} .'" style="float: right"/>';
$pd = $image.$product->description .'<a href="'.$product->{'buy-url'}.
'">...For more details and to buy it click here</a>';
$p = array('post_title' => $product->name,
'post_content' => $pd,
'post_status' => 'publish',
'post_author' => 1,
'post_category' =>array($_GET['cat']));
$pr = wp_insert_post( $p, $wp_error );
echo '<br/>posted...post ID is:'.$pr;
wp_reset_query(); // Restore global post data stomped by the_post().
}
}
}else{
echo 'please complete form';
$a = $a+1;
}
}
?>
<html>
<body>
<form action="catag.php" method="get">
<table>
<tr>
<td><label> Select a catagory from list:</label></td></tr>
<tr>
<?php
foreach($cat as $key=>$val){
echo '<tr><td><input type="radio" value="'.$val->cat_ID.'" name="cat" id="'.$val->cat_ID.'">'.$val->cat_name.'</td></tr>';
}
?>
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form><br>
</body>
</html>
You can not literally "pause" a php script, as php is executed on the server before the page even loads.
To execute any kind of a "pause" you would need to write your function in Javascript or other Client Side (Browser Executed) code, or send something like an Ajax request to a php page that would then update the current page on response.

Help creating an ajax method to add to basket

I have the following code that I want to turn into a silent ajax function so the page does not need to refresh, when a user adds a product the basket.
Currently I have the following code,
PHP
function showProduct($productId)
{
if (!$productId > 0)
{
redirect('home');
}
$this->load->model('Product_model');
$this->load->model('Checkout_model');
$this->data['items'] = $this->Checkout_model->GetProducts();
// Check to see if the Add To Bag button has been clicked.
if ($this->input->post('btnAddToBag'))
{
$derivativeId = $this->input->post('selDerivative-1');
$quantity = $this->input->post('selQuantity');
$derivative = $this->Product_model->GetProducts(array('pdId' => $derivativeId), 'small');
// Add item to shopping bag.
$attributes = $this->Product_model->GetProductDerivatives(array('pdId' => $derivativeId));
$this->Checkout_model->AddProduct($derivative, $attributes, $quantity);
$this->data['message'] = 'Item added to Shopping Bag.';
// Update Delivery Price
$this->Checkout_model->updateDelivery(49);
//get the bag details
}
$this->data["product_details"] = $this->Product_model->GetProducts(array('productId' => $productId, 'pdOrdering' => 1), 'detail');
$this->data['product_images'] = $this->Product_model->GetProductImages(array('productId' => $productId, 'ipPosition' => 'detail'));
//send the new filename to the view
//die(print_r($this->data['product_images']));
//die(print_r($this->data['sliderUrl']));
// Retrieve images for initial derivative.
$this->load->model('Attribute_model');
$this->data['derivative_images'] = $this->Attribute_model->GetAttributeValues(array('pdavProductDerivativeId' => $this->data["product_details"]->pdId), 'small', TRUE);;
$derivatives = $this->Product_model->GetProductDerivatives(array('pdProductId' => $productId));
$this->data["product_derivatives"] = $derivatives['derivatives'];
$this->data["product_attribute_names"] = $derivatives['attributeNames'];
// Retrieve details of this range.
$subRangeId = $this->data["product_details"]->productRangeId;
$this->data["sub_range_details"] = $this->Range_model->GetRanges(array('range.rangeId' => $subRangeId));
$rangeId = $this->data["sub_range_details"]->rangeParentId;
$this->data['active_menu_item'] = "subrange";
if ($rangeId == 0)
{
$rangeId = $subRangeId;
$this->data['active_menu_item'] = "full";
}
$this->data["range_details"] = $this->Range_model->GetRanges(array('range.rangeId' => $rangeId, 'range.rangeParentId' => 0), 'navigation');
if ($rangeId != $subRangeId)
$this->template->set_breadcrumb($this->data["range_details"]->rangeTitle, $this->data["range_details"]->rangePath);
//$this->data["rangePath"] = $this->uri->segment(1).'/';
$this->data["rangeId"] = $rangeId;
$this->data["subRangeId"] = $subRangeId;
// Retrieve list of sub ranges in this range.
$this->data["sub_ranges"] = $this->Range_model->GetRanges(array('range.rangeParentId' => $rangeId));
$this->data["individual_products"] = $this->Product_model->GetProducts(array('psiParentId' => $productId), 'small');
$this->data["related_products"] = $this->Product_model->GetRelatedProducts(array('product_related.prProductId' => $productId, 'ordering' => 'productActualPrice'), 'small');
$this->data['bestsellers'] = $this->Product_model->GetProducts(array('productBestSeller' => '1', 'range.rangeParentId' => $rangeId, 'ordering' => 'range.rangeOrder'), 'small');
$this->data["multibuy"] = $this->Product_model->GetProducts(array('psi.psiChildId' => $productId, 'productSavingType' => 'multi-buy'));
//$this->load->view('collection', $data);
if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest") {
$this->template
->build('product/quickview', $this->data); // views/product/product.php
}else{
$this->template
->set_layout('default') // application/views/layouts/default.php
->title(($this->data["product_details"]->productMetadataTitle != '' ? $this->data["product_details"]->productMetadataTitle : $this->data["product_details"]->productTitle))
->set_metadata('keywords', $this->data["product_details"]->productMetadataKeywords, 'meta')
->set_metadata('description', ($this->data["product_details"]->productMetadataDescription != '' ? $this->data["product_details"]->productMetadataDescription : $this->data["product_details"]->productShortDesc), 'meta')
->set_metadata('', site_url('assets/js/product.js'), 'js')
->set_metadata('', site_url('assets/js/jquery.nivo.slider.js'), 'js')
->set_metadata('', site_url('assets/js/slider.js'), 'js')
->set_partial('left-nav', 'blocks/ranges_sub_menu') // application/views/blocks/ranges_sub_menu.php
->set_breadcrumb($this->data["sub_range_details"]->rangeTitle, $this->data["sub_range_details"]->fullRangePath)
->set_breadcrumb($this->data["product_details"]->productTitle, $this->data["product_details"]->fullProductPath)
->build('product/product', $this->data); // views/product/product.php
}
}
HTML FORM
<?php echo form_open(current_url(), array('id' => 'frmProducts'), array('submitted' => '1')); ?>
<div class="formRow">
<label for="rattanType"><?php echo $product_attribute_names; ?> </label><br />
<?php
$options = array();
foreach ($product_derivatives as $derivative) :
$options[$derivative['derivativeId']] = $derivative['attributeValues'];
endforeach;
?>
<?php echo form_dropdown('selDerivative-1', $options, $product_details->pdId, 'class="select clear" id="selDerivative-1"'); ?>
</div>
<?php if (count($individual_products) > 0) : ?>
<div class="formRow">
<label for="itemType">Item</label><br />
<select class="select clear" id="selURL-1" name="selURL-1">
<option value="<?php echo current_url(); ?>">Full Set</option>
<?php foreach ($individual_products as $product) : ?>
<option value="<?php echo site_url($product->fullProductPath); ?>"><?php echo $product->productTitle; ?> - £<?php echo ($product->productSavingType != 'none' ? $product->productSavingPrice : $product->productPrice); ?></option>
<?php endforeach; ?>
</select>
<input id="btnGo-1" name="btnGo-1" type="submit" value="GO" />
</div>
<?php endif; ?>
<div class="formRow">
<label for="addQty">Quantity</label><br />
<?php
$options = array();
for ($i = 1; $i < 10; $i++) :
$options[$i] = $i;
endfor;
?>
<?php echo form_dropdown('selQuantity', $options, '1', 'class="small select clear"'); ?>
</div>
<input type="submit" value="add to bag" name="btnAddToBag" id="btnAddToBag" />
<?php echo form_close(); ?>
// Reset action of form when add to bag button is clicked.
$("#btnAddToBag").click(function () {
$("#frmProducts").attr("action","<?php echo current_url(); ?>");
});
How can I change this code that it makes an ajax request and updates the cart without refreshing the page?
You need to split off your basket display into another file so that you can use:
$.load()
Example basic usage:
$('#ShoppingCart').load('Cart.php', function() {
alert('Load was performed.');
});
<div id="ShoppingCart"> </div>
Or a little more like youve currently got it set up:
$("#btnAddToBag").click(function () {
$('#ShoppingCart').load('Cart.php', function() {
alert('Load was performed.');
});
});
Edit:
Re-reading your post, do you not want the cart to update atall?
In that case you would need to use $.post()
See: http://api.jquery.com/jQuery.post/
I have already answered a question for JSP/SERVLET here this one should work by changing the URL to a PHP page...
You need to make an XML Http request to the Servlet for that you need to make a XML Http object in the javascript in your HTML/PHP page
var myxmlhttpobj=new GetXmlHttpObject();
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
Now you need to make a request to the PHP from the javascript
var url="urlofPHPpage";
var para="parmeter1=value1&parameter2=valu2;
myxmlhttpobj.open("POST",url,true);
myxmlhttpobj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
myxmlhttpobj.setRequestHeader("Content-length", para.length);
myxmlhttpobj.setRequestHeader("Connection", "close");
myxmlhttpobj.onreadystatechange=ajaxComplete;
myxmlhttpobj.send(para);
At the PHP page you need to process the result and sent it back as string:
When the request comes back the myxmlhttpobj.onreadystatechange=ajaxComplete; will be called
function ajaxComplete(){
if(myxmlhttpobj.readyState==4){
///Display the result on the HTML/PHP Page BASKET
}
}
That should help...
Also have a look at jQuery Ajax API.

Categories