-4

I have a HTML file that has form:

<form id="su" class="signup" method="post" action="form.php" name="Sign Up" style='display: block'>

I know that form input value will send to form.php file, and webpage will redirect to form.php.

After form.php manipulated data from HTML file like $_POST['password'] and get a return value, how can I send return value to HTML page and redirect webpage to HTML.

I am not sure if I have a correct thinking. Because I saw someone said Ajax technique, I am new for web development, please give me advice.

What I did is about sign up form, data sent to php to do registration on database, if registration successes, it should send notification to customer.

2

2 Answers 2

1

Ajax is a good option to do this enter image description here

Here is a an Example

<form> 
First name: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>

this a simple form get data from HTML directly and process it in Script like this

  <script>
    function showHint(str) {
      if (str.length == 0) { 
         //make the txtHint value as Blank
          document.getElementById("txtHint").innerHTML = "";
          return;
       } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
          //status 200 mean it is OK
           if (this.readyState == 4 && this.status == 200) {
                document.getElementById("txtHint").innerHTML = this.responseText;
        }
    };
    //bass the value of textbox to php
    xmlhttp.open("GET", "gethint.php?q=" + str, true);
    xmlhttp.send();
 }
}
 </script>  

and the Php File seems to like this

      <?php
  // Array with names
  $a[] = "Anna";
  $a[] = "Brittany";
  $a[] = "Cinderella";
  $a[] = "Diana";
  $a[] = "Eva";

  // get the q parameter from URL
  $q = $_REQUEST["q"];

  $hint = "";

 // lookup all hints from array if $q is different from "" 
 if ($q !== "") {
   $q = strtolower($q);
   $len=strlen($q);
    foreach($a as $name) {
        if (stristr($q, substr($name, 0, $len))) {
            if ($hint === "") {
               $hint = $name;
             } else {
                $hint .= ", $name";
             }
         }
    }
 }

// Output "no suggestion" if no hint was found or output correct values 
 echo $hint === "" ? "no suggestion" : $hint;
?>

and i suggest that you see this awesome tut : Ajax And PHP

-2

You can use

echo $_COOKIES['']

to send data back to the client.

http://php.net/manual/en/features.cookies.php

1
  • 1
    Note that echoing user data directly is never safe. Always escape the data, for example using the inbuilt function htmlspecialchars
    – Drew Lemmy
    Commented Feb 4, 2017 at 23:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.