1.11M Members

PHP refreshing my page

 
0
 

Hey everyone,

I was under the inpression that PHP would refresh dynamically and not necessarily the whole page. When I make forms in PHP I am noticing the entire page gets refreshed before the new content is displayed. this is the oppsite of what I am trying to acheive. If I wanted that result I would just make 2 HTML pages. An example is on my own site right noe mtechenterprises.com. What language will give me what I want?

Thanks for the help

 
0
 

Can you show us your php responsible for generating your form? Normally, php does not refresh page. The only time the page will reload the page, when the form is submitted.

Most form processors are either written in PHP , ASP , and CGI . Although CGI was the most common form processors in the past, today PHP and ASP are the most common form processors.

If you don't want any page reload on submit, then you can use either or both ajax and jquery, but still jquery and ajax needs either PHP or ASP as form processor.

 
0
 

In addition to a java script reload, you can send a refresh header:

header("Refresh: 300;url='http://thepage.com/example'");

The browser will redirect after 300 seconds regardless of java script.

 
0
 

If you want data 'pushed' to the page, you'll need comet. This can also be simulated with regular ajax polling. If you want to update part of a page in response to an action, your best bet will be ajax if you need data from the server. However, it may be able to dealt with entirely with javascript, if you load php data into js variables for storage (e.g. json) on page load. Then actions access the data held in js. There can be problems with this last approach, depending on what you're trying to do.

If you go down the ajax route, I'd recommend using jquery as this provides a very user-friendly method of dealing with requests and responses.

 
0
 

Thank you for your responses. Below is the code from my own temporary landing page.

<!DOCTYPE html>
<title>MTech Enterprises  is Being Remodeled</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=.5, minimum-scale=.5, maximum-scale=2, target-densitydpi=device-dpi" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet" />
<link href="css/site.css" rel="stylesheet" />
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/slides.min.jquery.js"></script>
<script src="js/jquery.countdown.min.js"></script>
<script src="js/site.js"></script>
<body>
  <div class="slides" id="slides">
    <div class="slides-container">
      <div class="slides-slide"><img src="i/bg-1.jpg" alt="Women's Conference Flyer" width="1280" height="800" class="pseudo-bg" /></div>
      <div class="slides-slide"><img src="i/bg-2.jpg" alt="Marketing Website" width="1280" height="800" class="pseudo-bg" /></div>
      <div class="slides-slide"><img class="pseudo-bg" src="i/bg-3.jpg" alt="eBLast for online video company" /></div>
    </div>
  </div>
  <div class="l-main">
    <div class="textual">
      <h1 class="textual-title">MTech Enterprises</h1>
      <h2>Coming back really soon</h2>
      <p class="textual-p">We're giving our site a fresh new look for the fresh new year</p>
      <h2>Call 708-955-2382 for a FREE quote on your current project</h2>
      <p></p>
      <h3>Click <a href="https://www.facebook.com/pages/MTech-Enterprises/108125962594230?sk=photos_stream" target="_blank">here</a> to view our portfolio</h3>
      <ul class="countdown" id="countdown">
        <li class="countdown-col"><span class="countdown-digits" id="days"></span>Days</li>
        <li class="countdown-col"><span class="countdown-digits" id="hours"></span>Hours</li>
        <li class="countdown-col"><span class="countdown-digits" id="minutes"></span>Minutes</li>
        <li class="countdown-col"><span class="countdown-digits" id="seconds"></span>Seconds</li>
      </ul>
      <div class="subscr">
    <?php
if (isset($_POST['submit']))
{
$to = "dmiller@mtechenterprises.com";
$subject = "MTech Mailing List";
$message .= $_POST['email'];

mail ($to, $subject, $message);

echo "<p style='text-align:center;color:#fff; font-family: Arial, Helvetica, sans-serif; font-weight:bold; margin-right:15px'>Thank you. We appreciate your interest.</p>";

}
else 
{   
?>
    <form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <input type="submit" class="btn" value="Get in the know" name="submit"/>
        <input class="subscr-input" placeholder="Your email here" name="email" id="email"/>
        </form>
 <?php
}
?>
      </div>
      <p class="textual-small">Please provide us your email address so you can stay abreast of all our special offers.</p>
      <div class="social-wrap">
        <a href="https://www.facebook.com/pages/MTech-Enterprises/108125962594230"><span class="social social-fb"></span></a>
        <a href="https://twitter.com/creative_pro"><span class="social social-tw"></span></a>
        <a href="http://www.linkedin.com/profile/view?id=20158246&trk=tab_pro"><span class="social social-lin"></span></a>
      </div>
      <span class="copy">© 2013 MTech Enterprises All Rights Reserved</span>
    </div>
  </div>
</body>
 
0
 

So what are you trying to do? I can't see from the code above. Which bit is giving you problems?

 
0
 

RIght now my entire page refreshes (or at least it appears so). I just want the section in which the form is enclosed to refresh.

 
0
 

So the content of <div class="subscr">?
What do you need displayed once the form is sent? The message above the form?
I think we've already answered this - you need to use Ajax.

Get hold of jQuery, check out the .post and .ajax constructs.
Prepare a separate php file for processing your form data and to supply a response.

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: