34 users online (0 members and 34 guests)  


  Results 1 to 2 of 2

Related

  1. Replies: 0
  2. Upload File    Forum: CGI Perl Forum
    Replies: 0
  3. Checkboxes on form = mailto recipients    Forum: CGI Perl Forum
    Replies: 1
  4. How do I upload my file?    Forum: HTML Forum
    Replies: 3
  1. #1
    Bigmous's Avatar
    Junior Member

    Status
    Offline
    Join Date
    Dec 2008
    Location
    Sydney, Australia
    Posts
    27

    Question Form - checkboxes & file upload

    I have currently finished producing a form using php to abstract the data entered; as well as sending it to a particular address.

    1.Trouble displaying more than 1 checkbox's value. I'v got 4 checkboxes relating to different times suitable in the day. Unfortunately atm it'll only display the value of the last checkbox ticked and not the rest.

    2.My form also requires uploading a file and was wondering how do we manage it?

    PHP CODE IS AS FOLLOWS
    _______________________________________________________________

    <?php

    $where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));

    mail("email address","Subject","Form data:

    First Name: " . $_POST['first_name'] . "

    Last Name: " . $_POST['last_name'] . "

    Email: " . $_POST['email'] . "

    Street: " . $_POST['street'] . "

    Suburb: " . $_POST['suburb'] . "

    Post Code: " . $_POST['post_code'] . "

    Ethnicity: " . $_POST['ethnicity'] . "

    Date of Birth - Month: " . $_POST['dobm'] . "

    Date of Birth - Day: " . $_POST['dobd'] . "

    Date of Birth - Year: " . $_POST['doby'] . "

    Phone: " . $_POST['contact_number1'] . "

    Mobile: " . $_POST['contact_number2'] . "

    Suitable Contact Times: " . $_POST['time'] . "

    Are You Overseas?: " . $_POST['overseas'] . "

    Date of Return - Month: " . $_POST['backm'] . "

    Date of Return - Day: " . $_POST['backd'] . "

    Date of Return - Year: " . $_POST['backy'] . "

    How Did You Hear About Us: " . $_POST['hear'] . "

    Photo:

    Enquiry: " . $_POST['enquiry'] . "

    ");

    include("thankyou.html");

    ?>
    _________________________________________________________________

    Thanks
    Last edited by Bigmous; 09-11-2009 at 10:30 AM.

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Form - checkboxes & file upload

    Quote Originally Posted by Bigmous View Post
    1.Trouble displaying more than 1 checkbox's value. I'v got 4 checkboxes relating to different times suitable in the day. Unfortunately atm it'll only display the value of the last checkbox ticked and not the rest.
    The problem is in your HTML code. Make sure you the name of the checkboxes is similar to the following:
    thename[]
    The brackets will put the checkbox values into an array within the $_POST array. The other option you have is to name each checkbox with a unique name. Then all values will come across individually instead of in an array.

    Quote Originally Posted by Bigmous View Post
    2.My form also requires uploading a file and was wondering how do we manage it?
    To upload a file, the following needs to be added to your HTML code:

    In the form declaration, add:
    Code:
    enctype="multipart/form-data"
    Then within the form itself, add the following:
    Code:
    <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
    When the form is submitted, all the data you need to work with the file will be located within the $_FILES superglobal array.

    A couple things to remember when allowing files to be uploaded via a form:
    1. PHP has a set limit on the maximum file size allowed in the upload. The default is set to 3MB, but can be changed in the php.ini. If you are on a shared server, your hosting provider will most likely have to change it, but will more than likely not be willing to.
    2. The file is uploaded to a temporary location. If you do nothing with the $_FILES superglobal array, you will lose the file.
    3. Make sure you include error handling in your PHP code to verify the file has been uploaded. There is an error code that comes through that will tell you what the problem was.



Tags for this Thread