0

I was practicing PHP. I'm a learner. I'm just trying to find out how to make the info left in the input remain there when clicked, for special purposes. I tried using jquery to make that possible but it's not working.

Here's my html

<form method="post">
<label for="name">Name</label>
<input name="name" type="text" id="" placeholder="First Name" />
<input type="submit" value="submit now" id="submission" name="submit_now" />
</form>

Here's my PHP

<code>

<?php
      $Admin = array("Eric", "Emeka", "Faith", "Lucy", "Theressa", "Hillary", "Justice", "Kate", "Rob");
      $Users = array("Jonah", "Augustar", "Orma", "Edwin", "Kirk Franklin", "Michael Jackson", "Hopsin", "Nike");
      $blacklist = array("Kenny", "kenny");
      $key = 1;

      if ($_POST["submit_now"]){
      if($_POST["name"]){
      foreach($Admin as $val){
      if ($_POST["name"]==$val){
      echo "I know you ".$_POST["name"]." You're actually an Admin and have an awesome place in your own life or someone else's life";

      $key = 1;
    }
  }
  foreach($Users as $vall){
    if ($_POST["name"]==$vall){
      echo "I know you".$_POST["name"];
      $key = 2;
    }
  }
  foreach($blacklist as $valll){
    if ($_POST["name"]==$valll){
      echo "You've been banished ".$_POST["name"]." Leave and never return!";
      $key = 3;
    }
  }
  if ($key!=1 AND $key!=2 AND $key!=3){
    echo "<b style=\"color:red\">Sorry I don't know you...";
  }
}
 }

 ?>

And there's my jQuery

    <script>
    $(document).ready(function(){
  $("#submission").click(function(){
    $("#name").val();
    var a = $("#name").val();
    $("#name").attr("val", "a");
  });

})
  </script>

Please just let me know where I went wrong

Eric McWinNEr
  • 534
  • 6
  • 19

4 Answers4

0

If you want keep value entered in the input box after form submit, you can try like this

<input name="name" type="text" id="" value="<?php echo $_POST['name']; ?>" />
Shrikant Mavlankar
  • 1,145
  • 1
  • 8
  • 17
0

You just need to add the value part like:

<input type="text" name="name1" value="<?php echo $name1; ?>">
Lokesh Pandey
  • 1,739
  • 23
  • 50
0

Either you use AJAX (submission without the browser reloading the page) and you can set something like

<form method="post" onsubmit="return false;" .. />

so that the submission is not processed, and then capture the click event of the button you want to let the user submit, and send the data with jQuery.ajax()

OR

You use standard PHP and when you return the HTML from the server include something like:

<input type="text" name="name" value="<?php echo $_POST["name"]; ?>" />

and your page will be reloaded with the value the user submitted.

Fredster
  • 776
  • 1
  • 6
  • 16
  • 1
    Thanks a lot Fredster...I'll note that...I was practicing with wampserver so I'm virtually returning html to the page when the button is clicked. I just went straight to Shrikant's answer first from the comment section.... – Eric McWinNEr Jul 15 '16 at 09:52
0

You need to set the form attribut action='' for same page post or any other page link

<form action="" method="post" novalidate>
 <label for="name">Name</label>
 <input name="name" type="text" id="" placeholder="First Name" />
 <input type="submit" value="submit now" id="submission" name="submit_now" />
</form>
Joyson
  • 370
  • 4
  • 18