-6

My situation is this: I want to create a single form for the registration of new members. But, when people fill out the form and press the enter button, I don't want the data to be submitted. Instead, when people press the enter button they should go to another text field until the entire form is filled and can be written into the database. I would like a solution which uses only PHP code, not Javascript.

Here is my code:

<form name="form1" method="post" action="saveregistre.php">
  <table width="35%" border="1" align="center">
    <tr>
      <td colspan="3">Please fill the form bellow</td>
    </tr>
    <tr>
      <td width="21%">first name</td>
      <td width="2%">:</td>
      <td width="77%"><label>
        <input type="text" name="textfield" id="fname">
      </label></td>
    </tr>
    <tr>
      <td>last name</td>
      <td>:</td>
      <td><label>
        <input type="text" name="textfield" id="lname">
      </label></td>
    </tr>
    <tr>
      <td>age</td>
      <td>:</td>
      <td><label>
        <input type="text" name="textfield" id="age">
      </label></td>
    </tr>
    <tr>
      <td>date of birth</td>
      <td>:</td>
      <td><label>
        <input type="text" name="textfield" id="dobirth">
      </label></td>
    </tr>
    <tr>
      <td>home town</td>
      <td>:</td>
      <td><input type="text" name="textfield2" id="htown"></td>
    </tr>
    <tr>
      <td colspan="3"><label>
        <input type="submit" name="button" id="button" value="Submit">
      </label></td>
    </tr>
  </table>
</form>
Will Palmer
  • 5,742
  • 1
  • 26
  • 33
enrekan2011
  • 911
  • 1
  • 7
  • 6
  • 3
    PHP works on a server, javascript works on a client. What you want to implement - works on a client. So stop being capricious and write some JS ;-) – zerkms Dec 28 '11 at 01:45
  • You can not. Please understand what are different between client side and server side? – vietean Dec 28 '11 at 01:45
  • Is your goal to avoid having Javascript on the page, or do you just not want to hand-code any javascript? Though off-hand I know of no libraries which do so, it is possible that PHP libraries exist to assist in the generation of client-side code. Alternatively, this could be done on the server-side by having a page load every time- ie a "submit" every time, but re-generating the page until the form is complete. I agree with others that client-side is the way to go for this, and that Javascript is the best way to do client-side. Can you explain your reasons for wanting a "PHP only" solution? – Will Palmer Sep 17 '12 at 06:16

3 Answers3

1

This is impossible with PHP. PHP is on the server.

Info about server side

Info about javascript client side scripting

Javascript can easily accomplish this for you. See this question

Like I said, this is impossible with PHP alone, here's some php that echos the javascript.

In your section

echo '
<script type="text/javascript" language="javascript">
    function convertEnterToTab() {
      if(event.keyCode==13) {
        event.keyCode = 9;
      }
    }
    document.onkeydown = convertEnterToTab;    
  </script>
';
Community
  • 1
  • 1
Nate
  • 1,889
  • 1
  • 20
  • 40
  • thanks for quick reply Nate.... i dont want to use a java script into my form...i need to use a php code only...:(...can u help me how to make my form like i want..?huhuhu – enrekan2011 Dec 28 '11 at 04:34
  • Hello. Like I said though, this is impossible with PHP alone. You need a client side scripting language. – Nate Dec 28 '11 at 05:03
0

by default, the [ENTER] focus is on the submit button if its the only one on the page. here's a link http://mentaljetsam.wordpress.com/2007/04/23/submit-a-html-form-with-the-enter-key/

0

Your PHP code can not change behavior of web page on client side.

As other said, PHP runs on server.To interact with user in HTML form fields, javascript interaction is required.

I think you should read/study w3c documents first.

rkosegi
  • 14,165
  • 5
  • 50
  • 83