//Preparing --Start--function pageThis($max, $max_page_links, $query, $page_link){//Uncomment the next 4 lines if don't wish to use this as a function//$page_link="paged.php";//$max=30;//Maximum items per page (rows)//$max_page_links=10;//Maximum links number in the page//$query="select * from some_table";//Your query$num_stuff=mysql_num_rows(mysql_query($query));//Getting the total possible rowsif (isset($_GET['page'])&&$_GET['page']>0){$start=intval($_GET['page'])-1;//Now the page number make more sense (page=1 is actually the first page)$current_page=intval($_GET['page']);//Some cleaning (SQL Injection prevention, and get rid of negative numbers)}//If no parameters passed.. just give the first pageelse {$current_page=1;$start=0;}//If a large page numbre passed (more than there actually is) just give the last pageif ($current_page>ceil($num_stuff/$max)){$current_page=ceil($num_stuff/$max);$start=ceil($num_stuff/$max)-1;}$start*=$max;//Which row to start with$get_stuff_query.=" limit $start, $max";//Adding the limit//Preparing --End--//Actual paging --Start--if ($num_stuff>$max){//Is there any need for pagin?if ($current_page>1){//Making previous page & first page links when needed$previous_page=$current_page-1;//previousious means -1echo "<a style=\"text-decoration: none;\" href=\"".$page_link."page=1\">|<</a> ";//First page is the page number.. you guessed it right.. 1echo "<a style=\"text-decoration: none;\" href=\"".$page_link."page=$previous_page\"<<</a> ";}if ($current_page>$max_page_links/2){//Are we going far away from the first viewed page link?if (ceil($num_stuff/$max)-$current_page<(($max_page_links/2)+1)){//Are we getting closer to last viewed page link?$start_counter=$current_page-($max_page_links-(ceil($num_stuff/$max)-$current_page));//Yes, Then we need to view more page links$end_counter=ceil($num_stuff/$max);//And no need to view page links more than the query can bring}else{$start_counter=$current_page-(($max_page_links/2)-1);//No, then just view some links before the currentrent page$end_counter=$current_page+($max_page_links/2);//And some links after}}else{//Still in the first pages?$start_counter=1;//Start with page one$end_counter=$max_page_links;//Show only enough links}for ($i=$start_counter;$i<=$end_counter;$i++){//A loop for viewing the linksif ($i==$end_counter){//Is this the last link?if ($i==$current_page){//Are we actually on the last page? Because we don't need the | after the linkecho "<a style=\"color:blue;\" class=\"link\">".$i."</a>";//Then make it look like we're on that page}else{echo "<a class=\"link\" href=\"".$page_link."page=".$i."\">".$i."</a>";//Well yeah, it's the last link.. but we're not there yet.}}else{//Not the last page you say.. mmm.. then print normally (with | after the link)if ($i==$current_page){//Are we vewing this page?echo "<a style=\"color:blue;\" class=\"link\">".$i."</a> | ";//Make us know it}else{//Not viewing.. just a normal link (the most common case here)echo "<a class=\"link\" href=\"".$page_link."page=".$i."\">".$i."</a> | ";//Nothing to say}}}if ($current_page<ceil($num_stuff/$max)){//Making the next and last page links$next_page=$current_page+1;//Next means +1$last_page=ceil($num_stuff/$max);//and the last page is the page.. whell.. it's the last one the query can bringecho " <a style=\"text-decoration: none;\" href=\"".$page_link."page=$next_page\">>></a>";echo " <a style=\"text-decoration: none;\" href=\"".$page_link."page=$last_page\">>|</a>";}}}
Sunday, 8 July 2012
Very simple but very powerful (Web Development)
Contact Us form redirect to home page after submit (Web Development)
I have developed a contact us page and also PHP code that works perfect. Know the only problem is that after submitting the form it shows only "Message sent" on a new page. I want that after submitting the form page will redirect back to home page. It is only one page "Landing Page". Here is the PHP code.`
<?phpif(!$_POST) exit;$email = $_POST['email'];//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){$error.="Invalid email address entered";$errors=1;}if($errors==1) echo $error;else{$values = array ('name','email','message','phone');$required = array('name','email','message','phone');$your_email = "todd@toddandersonhomes.com";$email_subject = "Free Credit Report: ".$_POST['subject'];$email_content = "Following is the free credit report detail from client:\n";foreach($values as $key => $value){if(in_array($value,$required)){if ($key != 'subject' && $key != 'company') {if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }}$email_content .= $value.': '.$_POST[$value]."\n";}}if(@mail($your_email,$email_subject,$email_content)) {echo 'Message sent!';} else {echo 'ERROR!';}}?>
HTML Code:
<form action="contact.php" method="post"><div class="formele"><ul><li><label>Name:</label><input type="text" id="name" name="name" class="text2" /></li><li><label>Telephone:</label><input id="name" type="text" name="phone" class="text2" /></li><li><label>E-mail:</label><input id="name" type="text" name="email" class="text2" /></li><li><label>Address:</label><input id="name" type="text" name="message" class="text2" /></li><li class="button"><input type="image" type="text" src="images/submit.png" /></li></ul></div><!--Contact Form Ends Here --></form>
Here is the link of the page: http://www.designsblessing.com/Landingpages/
<?phpif(!$_POST) exit;$email = $_POST['email'];//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){$error.="Invalid email address entered";$errors=1;}if($errors==1) echo $error;else{$values = array ('name','email','message','phone');$required = array('name','email','message','phone');$your_email = "todd@toddandersonhomes.com";$email_subject = "Free Credit Report: ".$_POST['subject'];$email_content = "Following is the free credit report detail from client:\n";foreach($values as $key => $value){if(in_array($value,$required)){if ($key != 'subject' && $key != 'company') {if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }}$email_content .= $value.': '.$_POST[$value]."\n";}}if(@mail($your_email,$email_subject,$email_content)) {echo 'Message sent!';} else {echo 'ERROR!';}}?>
Subscribe to:
Posts (Atom)