Results 1 to 21 of 21

Thread: Check Box Php

  1. #1

    Check Box Php

    Hi all first post to the forum.
    I have been developing a form that has many radio buttons and have managed to output this to email using Php. Now I thought I would be clever and use check boxes for a question on credit card types.The user may have more than one card. I have spend three weekends now trying to get some Php code to make it output to the email. But this seems to be a different ball game. Although I have managed to get the radio buttons working I can not program in Php. I thought I got close on a number of occasions with the check box and had an email that displayed "Array" instead of the checked box values. Now I am quite confused. If any one could help with some Php for this I would be most grateful. This is my form without the submit side of it.

    <label><input type="checkbox" name="Credit[]" value="Amex" />
    Amex</label>
    <br />
    <label><input type="checkbox" name="Credit[]" value="Diners"/>
    Diners</label>
    <br />
    <label><input type="checkbox" name="Credit[]" value="Debit Card"/ >
    Debit Card </label>
    <br />
    <label><input type="checkbox" name="Credit[]" value="Mastercard" />
    Mastercard</label>
    <br />
    <label><input type="checkbox" name="Credit[]" value="None" />
    None</label>
    <br />
    <label><input type="checkbox" name="Credit[]" value="Visa" />
    Visa</label>

    Many Thanks
    Weka1

  2. #2
    Join Date
    Feb 2006
    Location
    Kusadasi, Turkey
    Posts
    3,273
    Note that a checkbox POST value will be null if it is not checked, it will be undefined.

    What does the following code print once you click on submit?

    var_dump($_POST['Credit']);
    Fraud Record - Stop Fraud Clients, Report Abusive Customers.
    █ Combine your efforts to fight misbehaving clients.

    HarzemDesign - Highest quality, well designed and carefully coded hosting designs. Not cheap though.
    █ Large and awesome portfolio, just visit and see!

  3. #3
    Join Date
    Nov 2003
    Location
    Marylebone, London, UK
    Posts
    526
    if (isset($_POST['Credit'])) {
    $cards = implode(":", $_POST['Credit']);
    }

    now use the variable $cards which has the data in it.

  4. #4
    Join Date
    Apr 2009
    Location
    Pittsburgh, Pennsylvania
    Posts
    582
    because you have the Credit[] it posts an array. You will need to cycle through...

    PHP Code:
    <?PHP
    echo "<pre>";
    print_r($_POST['Credit']);
    echo 
    "</pre>";
    and it would show them all..

    PHP Code:
    <?PHP

    foreach($_POST['Credit'] AS $c) {
        echo 
    "$c <br />";
    }
    i'm not sure how you're using the data, but this gives you the idea on how to manipulate it..

  5. #5
    Thanks everyone. I will have another shot and post back a reply. I'm a weekend warrior with the coding so will come back then.

    Thanks again
    Weka1

  6. #6
    Join Date
    Sep 2005
    Location
    In canada
    Posts
    3,213
    This will work for sure for it works for me

    Code:
    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }

  7. #7
    Hi Harzem,
    Thanks for your help....I get an error on the line of code---- Parse error: parse error, (etc) on line 250

    Weka1

  8. #8
    Hi Energizer Bunny
    Was hoping this would work butI also get an error....Parse error: parse error, (etc) on line 250

    Just to make sure you are aware the credit card check boxes are part of a larger form and posting comes at the end of the form

    Weka 1

  9. #9
    Hi Cselzer

    Thanks for the reply I am not sure what to do with what you have suggested. Warning...you are dealing with a complete dummy.With Php anyway.

    Weka1

  10. #10
    Join Date
    Sep 2005
    Location
    In canada
    Posts
    3,213
    What is your line 250 for you get parse error for multiple codes, maybe its still giving error from some previous code ?

    What i am assuming is you got Credit as name somewhere else on the form, try changing credit above to Creditpicked

    Cheers

  11. #11
    Hi Enerqizer Bunny,
    Thanks again I do appreciate the help. I do not have "credit" in the code any where else on the form. The only other place it is used is in text on the form. This is the php code as I tried it:
    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }
    This is the error:
    Parse error: parse error, unexpected T_IF in /var/www/vhosts/website.com/httpdocs/joinmail.php on line 250
    This is at the end of the form:
    //echo $message;

    @mail($sendmail, $subject, $message, $headers);
    header("location:confirmcontact.html");
    ?>

    I think this is the send bit of the form. At the begining it has this
    $name=$_POST['name'];
    $sendmail="[email protected]";
    etc
    This takes a user to the thank you page.
    I hope this gives you a better picture.
    Cheers Weka1

  12. #12
    Join Date
    Nov 2003
    Location
    Marylebone, London, UK
    Posts
    526
    check the few lines in the code BEFORE the line:

    if (is_array($_POST['Credit'])){


    the 'if' line above is fine, so something has probably not been written
    correctly BEFORE this line.

  13. #13
    Hi squirrelhost,
    This is code immediately before... I think this is just the display format for the credit card part of email.

    <td width='50%' height='30' align='left' valign='middle' bgcolor='#f1f1f1' style='font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: #000000;text-decoration: none;line-height: 16px;font-weight:normal;'>".

    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }

    Cheers Weka1

  14. #14
    Join Date
    Jun 2009
    Posts
    35
    I guess the line before if loop is an echo statement which ends with a full stop.
    Try by replacing it with semicolumn.
    That line does not end with a semicolumn.It is the actual problem.

    Hope this helps.
    Neseema M M
    Ezeelogin - The ultimate multiple server administration software.
    * Parallel shell * rm -rf protection * SSH logging * automated password changes * encrypted storage *
    AdMod.com - Delivering innovative web hosting solutions

  15. #15
    Thanks for that sorry I have taken so long to get back. I replaced the full stop and get an error message:

    Parse error: parse error, unexpected T_IF in /var/www/vhosts/k9-dog-training.com/httpdocs/joinmail.php on line 250

    Cheers Weka1

  16. #16
    Before I tried to add credit card info (Check Boxes) the form worked perfectly. The whole form is made up with radio buttons. I changed the forms Credit card button "Yes" or "No" to The Check boxes so users could indicate what Cards they have/use. So the code as described was added in the place where I had the radio buttons for credit cards.I thought it would be straight forward but no. As the form worked I can only assume that the problem is with the added code for check boxes.

    Cheers Weka1

  17. #17
    Join Date
    Nov 2009
    Location
    Toronto, Canada
    Posts
    735
    Small note: I don't think square brackets are really allowed to be in a field name in proper HTML. They can't easily be referenced in javascript for example.

  18. #18
    Join Date
    Sep 2005
    Location
    In canada
    Posts
    3,213
    Quote Originally Posted by Weka1 View Post
    Hi squirrelhost,
    This is code immediately before... I think this is just the display format for the credit card part of email.

    <td width='50%' height='30' align='left' valign='middle' bgcolor='#f1f1f1' style='font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: #000000;text-decoration: none;line-height: 16px;font-weight:normal;'>".

    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }

    Cheers Weka1

    That is just wrong from just looking at it.

    It should be something like this

    Code:
    echo "
    <td width='50%' height='30' align='left' valign='middle' bgcolor='#f1f1f1' style='font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: #000000;text-decoration: none;line-height: 16px;font-weight:normal;'>";
    
    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }
    or if its a php page and got html something like this :

    Code:
    <td width='50%' height='30' align='left' valign='middle' bgcolor='#f1f1f1' style='font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: #000000;text-decoration: none;line-height: 16px;font-weight:normal;'>
    
    <?php
    
    if (is_array($_POST['Credit'])){
    $Credit = implode(", ", $_POST['Credit']);
    echo '<br/><b>Credit:</b> ';
    echo $Credit;
    }
    
    ?>
    What i am trying to get at is , you cannot have html in php code without proper echoing the html part, i use mostly echo ' somehtmlcode' ; seems like here you are missing and are using format echo " somehtmlcode " ; and that td statement is not enslosed in an echo statement.

    Cause you cannot insert html in php without echoing it.

    @CanSpace , sorry but html can have w/e you can throw at it. And form fields do take [].

  19. #19
    Join Date
    Jun 2009
    Posts
    35
    Parse error: parse error, unexpected T_IF in /var/www/vhosts/k9-dog-training.com/httpdocs/joinmail.php on line 250
    This error mainly occurs if the lines before it is not properly closed or if the quotes there are not properly escaped.

    Will you please mind to post some lines before it.
    Neseema M M
    Ezeelogin - The ultimate multiple server administration software.
    * Parallel shell * rm -rf protection * SSH logging * automated password changes * encrypted storage *
    AdMod.com - Delivering innovative web hosting solutions

  20. #20
    Join Date
    May 2009
    Posts
    766
    Quote Originally Posted by CanSpace View Post
    Small note: I don't think square brackets are really allowed to be in a field name in proper HTML. They can't easily be referenced in javascript for example.
    Care to point out the documentation on this? PHP requires subscript operators on all form fields to be returned as arrays...doubt there would have been an oversight that large.

  21. #21
    Join Date
    May 2009
    Posts
    766
    Quote Originally Posted by Neseema M M View Post
    This error mainly occurs if the lines before it is not properly closed or if the quotes there are not properly escaped.

    Will you please mind to post some lines before it.
    I've found that a missing semi-colon is also a frequent culprit for this error.

Similar Threads

  1. how to check load via ssh and check files causing load ??
    By koolnhot in forum Hosting Security and Technology
    Replies: 5
    Last Post: 07-01-2009, 05:34 PM
  2. [Price-Check]Free-webhosting site[Price-Check]
    By SFA-Dark in forum Other Web Hosting Related Offers
    Replies: 0
    Last Post: 10-31-2004, 12:13 PM
  3. Replies: 35
    Last Post: 09-19-2004, 03:34 AM
  4. Spell Check, Grammar Check, Link Check
    By HostRefugee-Vince in forum Web Design and Content
    Replies: 5
    Last Post: 05-17-2004, 01:44 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
  •