#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    3
    Rep Power
    0

    ...in a lengthly form, is it possible to use PHP3 to automatically fill form fields with data that has already been entered into a previous place on the same form? ...or from a previously filled out form?
    ...likewise, is it possible to perform a math calculation on a number entered into a field and have the result automatically defaulted to another subsequent field?

    ...answers to these questions will be much appreciated.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    Perth West Australia
    Posts
    757
    Rep Power
    15
    Not sure if it can be done on the same page without re-sending the page to itself - but you can span 2 or more pages & php will remember the values from all form inputs - be careful not to use the same name for values in different pages as the second will overwrite the first.
    Try the example below - create 2 pages one called thisform.php3


    <html>
    <body>
    <form method=post action="page2.php3">
    enter number:<input type="text" name="num0" ><br>
    enter number:<input type="text" name="num1" ><br>
    enter text:<input type="text" name="yourtext" ><br>
    <input type="submit" name="submit">
    </form></html>

    and another called page2.php3 -

    <html>
    <body>
    <form method=post action="thisform.php3">
    num0 + num1:<input type="text" name="newnum0" value="<?php echo $num0 + $num1?>"><br>
    num1 x num0:<input type="text" name="newnum1" value="<?php echo $num0 * $num1?>"><br>
    <input type="text" name="newtext" value="<?php echo $yourtext; ?>"><br>
    <input type="submit" name="submit">
    </form></html>

    just look at the code to see how it works.


    ------------------
    Simon Wheeler
    FirePages -DHTML/PHP/MySQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Location
    Englewood, CO
    Posts
    30
    Rep Power
    15
    I'm not to clear on your first question; I can interpret it two ways, so I'll answer both:

    If you want the contents of a text field to be automatically entered into another text field on the same page as the user enters data into the first field, you'll have to use JavaScript (or similar)...I use a function document.onkeyup to check where a user is entering information and act on other form fields accordingly. You could use document.onkeyup to see on what form field (if any) the current focus is and change some other field based on that.

    To pass information from one form to another, have PHP print the values of the form elements as value="(value)" in the form elements of the new page.

    Like this:

    ...
    <INPUT TYPE='text' value='
    <?
    print "$stored_value"; // (or whatever)
    ?>
    ' LENGTH='10' MAXLENGTH='10'>
    ...etc...

    That will put in a text box with the value of $stored_value as it's default value.

    For the calculator problem, you'll use Javascript as described above, catching the onkeyup (or another onkey event) and performing your calculations on the fields of interest.

    The primary difference between handling activities via Javascript or PHP is the fact that Javascript can be used on the client side while PHP is strictly server side. That is, if you want your page to change without the user connecting to a server some way (like submitting a form or clicking a URL), you'll have to use a client-side scripting language like Javascript. If you want anything to happen after the user clicks submit or a URL, you can use PHP to process the request and send back HTML customized to your needs, including building custom Javascript code for the client. It sounds like you are primarily trying to change the contents of your site without the user submitting a form or clicking a URL. PHP will do nothing on the client side, therefore you need a client-side scripting language like Javascript.

    -TM

Similar Threads

  1. How to save form data to be recalled at a later date
    By Brutality in forum ColdFusion Development
    Replies: 3
    Last Post: February 8th, 2004, 03:31 PM
  2. Need help with some form data processing
    By wzhaoca in forum HTML Programming
    Replies: 2
    Last Post: February 2nd, 2004, 04:39 PM
  3. Need help with posting data onto a form
    By onLOoker in forum Perl Programming
    Replies: 2
    Last Post: January 25th, 2004, 09:58 PM
  4. HTTP Error 400: Bad Request, with basic form
    By crackwombat in forum PHP Development
    Replies: 1
    Last Post: January 23rd, 2004, 07:40 PM
  5. sending form field data
    By bellcom in forum PHP Development
    Replies: 1
    Last Post: January 19th, 2004, 04:39 PM

IMN logo majestic logo threadwatch logo seochat tools logo