Set frame height dynamically using javascript

Hi Geeks,
As I faced the problem in so many times for Set Iframe height dynamically using javascript or setting the Iframe height as per its content, If we add the fix height to Iframe tag directly then it just show the scrollbar in that height but sometime we don’t want to show the scrollable area in that Iframe then there are so complex situation to set the Iframe height for dynamic content and the height may vary or Iframe on content coming from database or any other source.

Now we don’t know that what exactly the height of iframe due to its dynamic content, I have tried So many solution for it and finally i left the issue and provide static height to Iframe, i tried all DOM related access manipulations and it just failed due to cross origin and CORS violation issues.
But one day for my selfishness in one project i faced same requirement with an Iframe and if i use the Iframe then it was saving my lot of time So i researched for 4-5 hours and finally i got perfect solution for it.
SOLUTION :

We need to implement the channel communication between parent window and Iframe window by passing the messages . It will work for same or cross domain origins

Note : we should have access for the Iframe source page.

we’ll post a message from the Iframe source page having a height value to the client domain
by using following script

Now where you are creating Iframe ,Go to that page
Like your Iframe is having like that

we have putted dummy url and set the style to overflow hidden and set frameborder as 0 .
and passed width as 100% but didn’t passed the height
so for getting calculated the height automatic please put the script as follow

This script will recieve the message passed from Iframe source origin and add the height of iframe dynamically .
Note : MY_IFRAME_ID is the id of Iframe we assumed , you can replace it with your Iframe id in Iframe and script both

Please comment below if you have any query related to this post or feature

form validation library in php

Hi Geeks,

Today i am sharing a generic class for

Form validation library in php

&  it also populate if form validation failed. First of all you can download the ‘form validation library in php’ by clicking on following url.

https://github.com/g10dra/form_validation_php/blob/master/class.validation.php

Now in this class you can validate the require,numeric,file-extension,match password & confirm password,validate url and other validation also.

It is having a validation with database like is_unique in mysql database where you need pass the db connection if you want to user is_unique validation.

Step 1: Include & Initialize the class in header or before your form s following:

Step 2: Create a HTML FORM

we are assuming that we have a form for add/edit ‘Advertise campaign’ form

Read the full comments in code

 

Step 3: Create a Table for advertise add/edit using following sql dump

Step 4: Now need to post the form and recieve data and show errors, Recieve post Before the HTML form

Please Comment If any problem in this. I’ll assist you to use this form validation library

Custom form validation in Codeigniter

Hi Geeks,
Today i am sharing you the Custom form validation example in codeigniter. Suppose we have a custom requirement to validate the data with our own custom rules like email already exist in database, So for this type on need can be resolve only with custom callback functions .these are the following steps to create a custom validation for any form.
Step 1: Form Layout form.php in views

Now , We have 4 fields in this form –
first name,last name, email and password
for validate these fields codeigniter already provided rules in form_validation library:
Some of the rules are following listed:
valid_email,required,valid_email,valid_url,min_length[5]|max_length[12] etc.

But Now we need to detect that email already registered in Database ,So we need to create a callback function for validating the email already check in database.

Note:Codeigniter itself providing rule for ‘value already exists in database’ but here our purpose is to demonstrate the custom form validation in codeigniter thats why we are assuming that this need a custom form validation.
Step 2. Create a callback to match the field’s value in database

Step 3. Load Form validation library in controller’s Action or Constructor method as following:

Step 4. Now pass the array of validation rules for the form in add method of user controller as following:

Please comment here if you have any query regarding to this form validation snippet or not cleared anything.

How to work with AngularJS as frontend and PHP MYSQL as backend

Hi Geeks,

In this tutorial you will learn that how to work with AngularJs as web frontend or in any hybrid app and get retrieve data from database using php and mysql. We have created restful webservice for return records to angular app.

Now steps for making a angularjs app with php and mysql –
Step 1) Create a database and table for fetching content from the table
Note: If you want to use existing database then select you db else create a new db with ‘news_db’ or whatever you want to take a db name.
Now Create a table named ‘news’ for getting data by following sql statement

Now Dump some dummy records by following insert statement:

Step 2) Create a file named config.php with following code

change credential according to your database and server host
Step 3) Now create a file for webservices named wsdl.php
Define Cross origin headers in this file by following code

Now code for getting data from database and provide in restful json format by following code

So complete Code for wsdl.php is following

Step 4) Now Start with frontend
Step for Getting data from database using angularjs as frontend and php & mysql as backed
make a file named index.html
include the script which i have attached with this post

Now make a ng-app with following html

make a html table format inside the div for getting data from datasource(php/mysql restful service) as following

Now put the script that call the restful web service and load data to the table

Now complete Code for index.html

Congratulations you have completed with this tutorial please provide comments for this tutorial. [viraldownloader id=146 text=’DOWNLOAD COMPLETE CODE’]

Array to Xml Conversion and Xml to Array Convert in PHP

Hi Geeks,
Today i am sharing you a code snippet for converting xml to array with attributes also and vice versa (Convert array to xml). This class is very useful to parse rss feed and to make rss feed in php programming.

In this code snippet we have made a class to convert array XML using php code and also retaining its attibues stored into array . It returns the XML in form of DOMDocument class for further manipulation. This class will throw exception if the tag name or attribute name has illegal characters.

Usage of this class:

A. Steps for Convert Array to Xml

1.Create a class named Array2XML with following code in file Array2XML.php

2. Now Include the class

3. Defining Array or get it from database then call the createXML method for generating xml file

Now Call createXML method as following

B. Steps for Convert Xml to Array

1. Define the xml oe get the xml string into a varribale

2.Now call the XML_TO_ARR function as following

[viraldownloader id=138 text=’DOWNLOAD COMPLETE CODE’]

CONVERT HTML TO PDF IN CODEIGNITER Using MPDF

Hi Geeks,
Today I am Sharing you the code for making pdf or download pdf files in codeigniter. In this Code snippet we have used the MPDF Kit for generating pdf of html views or dynamic templates. So Following are the steps to create/convert HTML to PDF In Codeigniter using MPDF

Prerequisites :- GD LIBRARY SHOULD BE ACTIVE ON YOUR WEB SERVER

Step 1: Download the Mpdf  Class and methods from here or  https://www.mediafire.com/?9qmqaw2yqlo5caa
Now extract the zip file and put the mpdf folder to application >> third_party folder (this folder Exists in Application folder in codeigniter app )
Step 2. Now make a ci library to call/communicate the mpdf methods and classes from your ci controllers

Now go to libraries folder in application folder and create a file named : M_pdf.php having following code snippet.

Step 3: Now in any of your controller where you want to use or convert the view to pdf output

You can see the calling of our created libary by loading the libarray using this->load_library, and pass the data whatever you required in your view or get the data from model and just pass to your pdf view and use/render that data in your view just like a normal view and controllers.

for sample , We have created a method named save_download having following code

 

By using this code you will able to make a functionality to convert html to pdf in codeigniter:
If you face any struggle in this please Comment below – Thanks & Cheers 🙂

Progress bar for php form post , Download the Code

Hi Geeks,
Now php has a feature for tracking the progress of multipart form submit. we can show the progress in percentage for user convenience .you can download the source code if you want to create progress bar in php form.
Following are the steps to create a progress bar for php form post.
Step 1. Add script and css for upload progress functionality working

Step 2. Form Tag should look like

Note: form id we have used myform so if you want to change the form id then you need to change in upload_script.js file also

Step 3. Add the placement for showing progress bar

Step  4. In your upload or form post action you can add your code for demo purpose we have use as following:

[viraldownloader id=126 text=’Download the Source code by sharing us on facebook.’]

Text to Image Convert using php code . Download source Code

Hi Geeks,
In this tutorial we will learn that how to Create and save dynamic image in php using gd library or Text to Image Convert using php code . in this example we have a requirement to create a image with specific width and height and specific background and watermark also.
So that we have created a PHP Class to generate and save the image to specific folder or path.
please follow the steps to achive this task.
Step 1. Create a class file for generate image with name class.img.php with following code:

Step 2. make another php file with any name.
and include the class file as follow:

Now create a instance of img class with font file names and sizes as following :

Init with font files and font sizes as follow:

Now generate a single image as follow:

Generate multiple images in loop as following code :

Complete Code of above snippets:

[viraldownloader id=113 text=’Download the Complete Code by Sharing this post and click on generate button after sharing’]

Note: please confirm GD library on your php server. and create a images folder in project with 755 or 775 or 777 permissions.

 

How to make a news aggregator website

Hi Geeks,
I am Sharing you the code for reading a rss feed using php script.
Following are the Steps to make a news aggregator website using rss reader in php
Step 1: Create a form having Rss Urls in select box as following

Step 2. Php code to recieve the submitted post and rss url. and get the rss output in object and parse the feed or rss using the dom document class and accessing the properties as following:

Final Complete Code:

Conclusion : Select your category and click on go button and you will see the fetched news from rss feed.

read rss using php script
read rss using php script