Results 1 to 2 of 2

Thread: php form submitting

  1. #1
    Join Date
    Jun 2010
    Posts
    243

    php form submitting

    I have a php form, and have about 15 fields. Right now, I am submitting the fields to the form_send.php as:

    PHP Code:
    $name $_POST['name']; 
    $lastName $_POST['lastName']; 
    $email $_POST['email']; 
    $phone1 $_POST['phone1']; 
    $phone2 $_POST['phone2']; 
    $phone3 $_POST['phone3']; 
    $business $_POST['business']; 
    What would be a quicker, more efficient way? Would I use arrays, or something of the sort? Or can I get each field, and set it to the form field name, so I only need one line of code?

    Thanks.

  2. #2
    Join Date
    Apr 2009
    Location
    The toon
    Posts
    1,225
    The contents of a posted form is stored in a predefined variable $_POST (Its data is stored as an array)

    Although its not required you should assign the values to a variable so you can perform some validation process on the values before processing further. I mentioned its not required as you can use the $_POST directly in place of the variable but I prefer to lay out my POSTS as you have done when coding procedurally.

    The other way would be to create a method in a class (OOP) which processes the POSTED data. You will still have to pass in the $_POST array but you could automate some the assignment and then reuse the class in other projects.

    For example you could loop through the $_POST array and using Variable Variable names...

    PHP Code:
    foreach($_POST as $key=>$value){

    $
    $key $value;


    NOTE: The double $$. This creates a variable from your KEY names in this example.

    To summarise your not doing anything wrong.

    There is always more than one way to skin a cat and each has their own merits

Similar Threads

  1. Help!! How to add a thank you page in html when submitting a form
    By clarky18 in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 24 Jul 2009, 06:08 AM
  2. form submitting to iframe.
    By helenearth in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 24 Feb 2009, 12:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •