#1
  1. No Profile Picture
    luisf
    Guest
    Devshed Newbie (0 - 499 posts)
    Is there an array in PHP that keeps all the variables that the user entered in the form, like $name, $email, etc?

    The purpose is: send an email to the webmaster saying:

    $name: John Richard
    $email: john@richard.com

    So, if I chance the name of the variables, or if I add another variable in the form.. it works..


    Thanks
    Luís
  2. #2
  3. No Profile Picture
    Hans
    Guest
    Devshed Newbie (0 - 499 posts)
    I don't know what your problem is, but form data allready gets passed to the result page in subsequent variables.

    So if you build a form like this

    <form method="POST" action="result.php" name="mailform">
    Name:<input type="text" size="30" name="frm_name"><br>
    Email:<input type="text" size="30" name="frm_email"><br>
    <input type="submit">
    </form>

    And you would submit this form with John Richard as Name and john@richard.com as email, the variables $frm_name and $frm_email contain the data entered in the form, in this case:

    $frm_name="John Richard" $frm_email="john@richard.com"




    [This message has been edited by Hans (edited 12-08-99).]
  4. #3
  5. No Profile Picture
    luisf
    Guest
    Devshed Newbie (0 - 499 posts)
    I need an array that keeps all the names and values of the form.

    So, I don't need to know all the variable names to send the e-mail, because I'll have all the form field values in this array..

    In perl, I would get the string "?name=value&name2=value", split and put it in an array..

    How can I do it in PHP??

    Thanks
    luis
  6. #4
  7. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Check the manual for $PHP_POST_VARS
  8. #5
  9. No Profile Picture
    Darguz
    Guest
    Devshed Newbie (0 - 499 posts)
    Actually, it's $HTTP_POST_VARS if your form uses the POST method, $HTTP_GET_VARS for the GET method.


    --
    Alan Little
    Holotech Web Design
    http://www.holotech.net/

    [This message has been edited by Darguz (edited 12-08-99).]
  10. #6
  11. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks, Alan. Can blame my memory on all the cough medicine

    Hey, I knew what I /meant/ to write....
  12. #7
  13. No Profile Picture
    luisf
    Guest
    Devshed Newbie (0 - 499 posts)
    So..

    I put the command

    <? print "$HTTP_POST_VARS - $HTTP_GET_VARS"; ?>

    and it prints

    Array - Array


    So.. I think these stuff is not available in my ISP... or am I doing something wrong?
  14. #8
  15. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    No, that's what you should get :0

    $HTTP_POST_VARS (and GET) are arrays. They contain in data passed by POST and GET methods respectively, with the name/value pairs as the index and data respectively.

    For example, if you pass the query string ?this=that&those=these
    then $HTTP_GET_VARS[this] would contain the value "that" and $HTTP_GET_VARS[those] would contain the value "these"

    Alternately, if you use a form you would use $HTTP_POST_VARS instead. In your application, all you would need to do is to use EACH across the $HTTP_POST_VARS array to get the keys (since you say you want to be able to change the form.)

    HTH

    Rod
  16. #9
  17. No Profile Picture
    Darguz
    Guest
    Devshed Newbie (0 - 499 posts)
    $HTTP_POST_VARS and $HTTP_GET_VARS are associative arrays (see the documentation for a description), containing the field names and values passed from your form. Use the each() construct to walk through them:

    while(list($var, $val) = each($HTTP_POST_VARS)) {
    [do stuff]
    }

    On each iteration of the loop, $var and $val will have the name and value, respectively, of a field in your form.

    ------------------
    Alan Little
    Holotech Web Design
    www.holotech.net/


    [This message has been edited by Darguz (edited 12-09-99).]

    [This message has been edited by Darguz (edited 12-09-99).]
  18. #10
  19. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    Isn't that what I said
  20. #11
  21. No Profile Picture
    PAV
    Guest
    Devshed Newbie (0 - 499 posts)
    But what if you get another array inside the form from, for example, multiple checkboxes/selects within a group?
    That gets a bit more complicated when only using HTTP_POST_VARS.
    Why not just catch all the variables (by name) on a reload (after submit) of the page on which you then also perform a mail() function and clear up the form again.
    I have good experience with that. Anyone any other ideas?

    Regards, Peter
  22. #12
  23. No Profile Picture
    rod k
    Guest
    Devshed Newbie (0 - 499 posts)
    PAV,

    You make good points. In fact, that is exactly what I do.

    However, go back and read the original question. He wants to be able to add a field to the form without modifying the action script. To do that you have to have your form in an array, either one he creates or $HTTP_POST_VARS.

    I don't mean this as a flame, but I've read many posts from you recently, and you give good advice except that your responses seem to not take into account special needs as defined by the person posting the question.

    The way you have solved a problem is not always the BEST way for everyone.
  24. #13
  25. No Profile Picture
    PAV
    Guest
    Devshed Newbie (0 - 499 posts)
    I'm sorry if that's the impression I made, it was surely not my intention to do so...

    But isn't this still a discussion forum?
  26. #14
  27. No Profile Picture
    luisf
    Guest
    Devshed Newbie (0 - 499 posts)
    Thanks guys!

    Now.. that worked.. you're the best. Now, I don't know if I dedicate myself to ASP or to PHP.

    But.. it's subject for another discussion..

    Thanks
    Luís
  28. #15
  29. No Profile Picture
    SneakyDave
    Guest
    Devshed Newbie (0 - 499 posts)
    Maybe this won't work with what you want to do, but you could NAME all your input fields something like FIELD[], which will store all the form fields into the array FIELD, and can be accessed with a for loop like:

    for($x=0;$x<$count($FIELD);$x++)
    {
    do stuff for each $FIELD[$x]
    }

    You wouldn't know what each value was for though, is the only problem.

IMN logo majestic logo threadwatch logo seochat tools logo