Practical Web Applications for Daily Living…
Posts tagged Php
Code Igniter Ajax Form
Sep 5th
$j(document).ready(function(){
$j("form").submit(function(e) {
e.preventDefault();
$j.post("/index.php/home/submitmessage", { firstname: $j("#firstname").val(), lastname: $j("#lastname").val(), address: $j("#address").val(), email: $j("#email").val(), confirmemail: $j("#confirmemail").val() , telephone: $j("#telephone").val(), mobile: $j("#mobile").val(),message: $j("#message").val() }, function (data) {
alert(data);
});
});
});
in application/config/constant
define(‘IS_AJAX’, isset($_SERVER[‘HTTP_X_REQUESTED_WITH’]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH’]) == ‘xmlhttprequest’);
in the controller
{
//load form validation
$this->load->library(‘form_validation’);
//set form rules
$this->form_validation->set_rules(‘firstname’, ‘Firstname’, ‘required’);
$this->form_validation->set_rules(‘lastname’, ‘Lastname’, ‘required’);
$this->form_validation->set_rules(‘email’, ‘Email’, ‘required|valid_email|matches[confirmemail]‘);
$this->form_validation->set_rules(‘confirmemail’, ‘Confirm Email’, ‘required|valid_email’);
$this->form_validation->set_rules(‘address’, ‘Address’, ‘required’);
$this->form_validation->set_rules(‘message’, ‘Message’, ‘required’);
//run form validation
$success = $this->form_validation->run();
//set username variable
$firstname = $this->input->post(‘firstname’);
$lastname = $this->input->post(‘lastname’);
$email = $this->input->post(‘email’);
$address = $this->input->post(‘address’);
$message = $firstname." ".$lastname."\n";
$message .= "Tel:".$this->input->post(‘telephone’)." | Mobile:".$this->input->post(‘mobile’)."\n";
$message .= $address."\n";
$message .= $this->input->post(‘message’);
$msg = $message;
//if the validation was a success
if ((IS_AJAX && $success) || (!IS_AJAX && $success)) {
$this->load->library(‘email’);
$this->email->from($email, $firstname." ".$lastname);
$this->email->to(‘juliusbacosa@gmail.com’);
$this->email->subject(‘Message from Weekee’);
$this->email->message($msg);
$this->email->send();
echo "Congradulations {$firstname}, your form was accepted!";
}
//if validation failed
else { echo strip_tags(validation_errors()); }
}
Copy and Paste Now!!!!
Jquery Ajax Codeigniter
Sep 1st
In your View
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
jQuery(‘#x’).click(function(){
jQuery("#content").empty().html(‘<img src="http://juliusbacosachronicles.com/wp-content/themes/mystique/images/workstation.jpg" />’);
var num = 8;
jQuery(‘#content’).load("index.php/welcome/jajax/"+num,function(str){});
});
});
// Code that uses other library’s $ can follow here.
</script>
then the div to hold the content
In your Controller
{
parent::Controller();
$this->load->helper(‘url’);
}
function index()
{
$this->load->view(‘welcome_message’);
}
function jajax($num)
{
$results[‘xxx’] = $num*111;
$this->load->view(‘Ajax_record’,$results);
//get the record from the database
}
then for the view Ajax_record
Retrieving data from Model and accessing the database is still the same.
Byeee….
Setting Up Contact Form within Static Block in Magento
Aug 31st
Just put this within your static block
<ul>
<li>
<div class="input-box">
<div><label for="name">Name <span class="required">*</span></label> <input id="name" class="required-entry input-text" title="Name" name="name" type="text" /></div>
<div class="input-box"><label for="email">Email <span class="required">*</span></label></div>
<div><input id="email" class="required-entry input-text validate-email" title="Email" name="email" type="text" /></div>
<div class="input-box"><label for="telephone">Telephone</label><br /> <input id="telephone" class="input-text" title="Telephone" name="telephone" type="text" /></div>
<div class="input-box"><label for="comment">Comment</label><br /> <textarea id="comment" class="input-text" style="height: 150px; width: 525px;" title="Comment" cols="50" rows="5" name="comment"></textarea></div>
</div>
</li>
</ul>
</fieldset>
<div class="button-set">
<p class="required">* Required</p>
<input id="hideit" style="display:none !important;" name="hideit" type="text" /> <button class="form-button"><span>Submit</span></button></div>
</form>
<script type="text/javascript">// <![CDATA[
var contactForm = new VarienForm(‘contactForm’, true);
// ]]></script>
And adding fields just put normal fields like how to do it in normal html forms,
then add the variables in the Email Template that you will be using
which can be found at system>email transaction>
next thing is to go to system>Generals>Contacts> setup where the email should be sent.
Changing Style of Parent Element of an HTML form input with Javascript
Aug 29th
The html input is a checkbox, I want to let the li be in highlight mode if the checkbox is checked.
<input type="checkbox" name="dishs[]" value="<?php echo $listdish[‘dish_name’]; ?>" onclick="checktolimit(this);"> <?php echo $listdish[‘dish_name’]; ?>
</li>
The javascript for this is.
if(obj.checked){
obj.parentNode.className=’selectactive’;
}else{
obj.parentNode.className=’selectnotactive’;
}
}
where selectnotactive and selectactive are class names in your style.css or whatever you call it.
Sleeping in 3,2,1…
Configurable Product Magento, switch view more images solved
Aug 22nd
Once again, I’ve managed to solve one fuzzy client request and stayed the weekend to kick this functionality into action.
My confidence in building website functionalities in the web is bursting that there is no impossible for me already, it just depends in time and of course your budget
well…. as usual I am sharing some code snippet that could help some fellow developers out there.
This is to replace the contents within the .more-views class in media.phtml of the product details.
where numx is the color attribute of the configurable product. this numx also is what I named the class populated hidden within the product detail page.
And is being rendered by this code
$product = Mage::getModel(‘catalog/product’);
$parent = $product->load($_product->getId());
$children = Mage::getModel(‘catalog/product_type_configurable’)->getUsedProductCollection($parent);
$xxx = $parent->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($parent);
foreach($children as $child){
$child = $product->load($child->getId()); ?>
<div style="display:none;">
<a href="<?php echo $this->helper(‘catalog/image’)->init($child, ‘image’); ?>" id="<?php echo "link".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>">
<img src="<?php echo $this->helper(‘catalog/image’)->init($child, ‘image’); ?>" id="<?php echo "img".$child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>" />
</a>
</div>
<div style="display:none;">
<div class=’<?php echo $child->getResource()->getAttribute(‘Color’)->getFrontend()->getValue($child); ?>‘>
<h2><?php echo $this->__(‘mouse over image to zoom’) ?></h2>
<ul>
<li>
<?php
$assoc_product = Mage::getModel(‘catalog/product’)->load($child->getId());
foreach($assoc_product->getMediaGalleryImages() as $assoc_product_img){ ?>
<a href="<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘image’, $assoc_product_img->getFile()); ?>" title="<?php echo $assoc_product->getName();?>" onclick="$(’image’).src = this.href; $(’imagex’).src = this.href; return false;">
<img src="<?php echo $this->helper(‘catalog/image’)->init($assoc_product, ‘thumbnail’, $assoc_product_img->getFile())->resize(70, 70); ?>" alt="<?php echo $this->htmlEscape($assoc_product_img->getLabel()) ?>" title="<?php echo $this->htmlEscape($assoc_product_img->getLabel()) ?>"/>
</a>
</li>
<?php } ?>
</div>
</div>
<?php } ?>
Ofcourse only demi Gods can understand this without proper explaination. Just PM me if you need something like this.
As I have search the web, I can’t find any solution in magento with this functionality.
This whole project is way beyond the clients budget. Lucky Him
Display more Attribute in Table Grid of Group Product Details in Magento
Aug 21st
Go to frontend/base/default/template/catalog/product/view/type/grouped.html
Add this code to the head of the table
<th class="a-right"><?php echo $this->__(‘Height’) ?></th>
insert this code in the table body:
where ’sign_width’ and ’sign_height’ are attribute names.
<td><?php echo $this->htmlEscape($_item->getData(’sign_height’)); ?></td>
enjoy!!!
How do you use configurable products versus group products in magento?
Zend framework, magento, webpage drafts
Aug 20th
There is a high possibility that I can’t have my first fully functional mini cms zend application, I have to spend every precious time to finish a large queue of customized ecommerce websites and complex cms websites.
Going to take a bath in 3, 2, 1 ….
Zend framework on Saturday
Aug 18th
Currently I am uploading another batch of magento files to be deployed live, and I am so sleepy right now… well… anyway… This friday we don’t to have work because we are going to a company relaxation day, because our skins are turning green already due to work radiation… so after friday, the whole saturday.. I will try to implement a zend application so I can have a taste of it before deploying a heavy weight web app, and also to compare my experience in asp.net mvc development.
I was wondering if there are any tools that can help unit test zend framework apps, of can I even use castle project for them, I don’t know yet. Are zend frameworks applications a test driven design one… opssss… files are almost done uploading in 3, 2, 1, byeeee…..
Code Igniter instead of Magento
Aug 18th
There are some situations where you need to take a cab instead of taking MRT. The other day, I decided to code an online transaction from scratch and it took me 20 hours to do the backend and frontend using code igniter instead of magento, If I use magento to implement it, the complexity in tweaking magento will add me more stress. Thank God to understanding of MVC pattern I rapidly develop the Application in no time at all compared to the complexity and stress magento is giving me everytime a client what some fancy functionality.
I’ve finally appreciated the value of Rapid Application Development tools like Code Igniter.
F and b website Singapore
Aug 17th
Last night seems to be a very long night. There was a client who come to us and she doesn’t know about web development and ecommerce especially for foods and beverages type of online transaction, I was not familiar with this part of online transaction before so I just showed here a solution what here client wants, turns out the solution I proposed to her which is magento is quite limited or I still have to dig again on the core magento codes to achieve want they want. So I decided to better code the entire transaction from scratch, thanks to my code igniter capabilities I’ve manage to put the backend side the whole night, actually I slept around 4, starting from 8pm – 4am in the morning. Tonight I will finish the backend to kick this project away from my face.
Thanks to code igniter people for the resources I’ve found online.
Taking a bath in 3,2,1…
