开发者

handling checkbox values in email form with php

I have gone through a bunch of question posts, and found one person with the same issue as me, but the answer he/she received I did not find to help at all.

I created a form which uses checkboxes. Once submitted my entire form is processed beautifully and I do receive the mail, but when it comes to the checkboxes it only displays "Array" in the email in stead of the checked checkbox values....

What am I doing wrong?

HTML Form Code: as requested, the full form

                                        <form name="busquoteform" method="post" action="FormToEmail.php">
            <fieldset>
                <legend>Contact Information</legend>
                    <table width="100%">
                        <tr>
                            <td width="40%">
                                <label><strong>Name *:</strong></label><br/>
                                <input name="name" type="text" id="name" value=""  />
                            </td>
                            <td width="10%">&nbsp;</td>
                            <td width="40%">
                                <label><strong>Lastname *:</strong></label><br />
                                <input name="lname" type="text" id="lname" value=""  />
                            </td>
                        </tr>
                     </table>
                     <table width="100%">
                        <tr>
                            <td width="25%">
                                <label><strong>Contact Number:</strong></label><br/>
                                <input name="contactno" type="text" id="contactno" value=""  />
                            </td>
                            <td width="25%">
                                <label><strong>Mobile Number * </strong></label><br/>
                                <input name="mobno" type="text" id="mobno" value=""  />
                            </td>
                            <td width="40%">
                                <label><strong>Email *:</strong></label><br/>
                                <input name="email" type="text" id="email" value=""  />
                            </td>
                        </tr>
                    </table>
                </fieldset>
                    <br/>
                <fieldset>
                <legend>Company Information</legend>
                    <table width="100%">
                        <tr>
                            <td width="40%">
                                <label><strong>Company Name *:</strong></label><br/>
                                <input name="compname" type="text" id="compname" value=""  />
                            </td>
                            <td width="10%">
                                <label><strong>Position Held *:</strong></label><br />
                                <input name="position" type="text" id="position" value=""  />
                            </td>
                            <td width="40%">
                            </td>
                        </tr>
                     </table>
                     <table width="100%">
                        <tr>
                            <td width="16%">
                                <label><strong>Company Address*:</strong></label><br/><br/><br/><br/>
                            </td>
                            <td width="2%">
                            </td>
                            <td>
                                <input name="street" type="text" id="street" value="Street" size="30"  /><br/>
                                <input name="suburb" type="text" id="suburb" value="Suburb" size="30" /><br/>
                                <input name="city" type="text" id="city" value="City" size="30" /><br/>
                                <input name="code" type="text" id="code" value="Postal Code" size="10"  /><br/>
                            </td>
                        </tr>
                      </table>
            </fieldset>
                <br/>
            <fieldset>
                <legend>Project Information</legend>
                    <table>
                        <tr>
                            <td>
                                <label><strong>Service Type/s*:</strong></label><br/>
                                Please select all applicable types.
                            </td>
                        </tr>
                        <tr>
                            <td>
                                Graphic Design&nbsp;<input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />&nbsp;&nbsp;&nbsp;&nbsp;
                                Web Development&nbsp;<input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />&nbsp;&nbsp;&nbsp;&nbsp;
                                Application Development&nbsp;<input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />&nbsp;&nbsp;&nbsp;&nbsp;
                                Embroidery&nbsp;<input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />&nbsp;&nbsp;&nbsp;&nbsp;
                                Engraving&nbsp;<input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <label><strong>Please supply a detailed description of your requirem开发者_如何学Pythonents*:</strong></label><br/>
                                <textarea name="projectDes" cols="60" rows="10" id="projectDes"></textarea>
                                <br/><br/>
                              <input name="quoteBus" type="submit" class="ZD-button" value="Send Request"/>
                            </td>
                        </tr>
                    </table>
            </fieldset>
         </form>

and the php processing code:

                    $mailBody = "Name : ".$_REQUEST['name']. "&nbsp; ".$_REQUEST['lname'].
                                " <br/>Email : ".$_REQUEST['email'].
                                " <br/>Contact No : ".$_REQUEST['contactno']. "&nbsp;&nbsp;Mobile No: ".$_REQUEST['mobno']. 
                                "<br/><br/>Company Name : ".$_REQUEST['compname']. 
                                " <br/>Postion Held : ".$_REQUEST['position']. 
                                "<br/><br/>Company Address : <br/>".$_REQUEST['street']."<br/>".$_REQUEST['suburb']."<br/>".$_REQUEST['city']."<br/>".$_REQUEST['code'].
                                "<br/><br/> Service Type/s :" .(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])."<br />".
                                "<br/><br/>Details of Project : ".$_REQUEST['projectDes'];

I've also tried: "

Service Type/s :" .$serviceType = $_POST["serviceType"];$serviceType = implode(', ', $serviceType);"

".

and also does not seem to work...

I got this code from a project my hubby did a while back - but he is not a php developer, he's into Java...

Help Please?


Update

I just tried your code and it works fine, and results what you want. So can you please show your <form> tag.

Code that I tested

<?php

echo (is_array($_REQUEST['serviceType']) ? implode("\n", $_REQUEST['serviceType']) : $_REQUEST['serviceType']);

?>


<form action="" method="post">

    Graphic Design&nbsp;<input name="serviceType[]" id="design" type="checkbox" value="Graphic Design" />&nbsp;&nbsp;&nbsp;&nbsp;
    Web Development&nbsp;<input name="serviceType[]" id="webdev" type="checkbox" value="Web Development" />&nbsp;&nbsp;&nbsp;&nbsp;
    Application Development&nbsp;<input name="serviceType[]" id="appdev" type="checkbox" value="App Development" />&nbsp;&nbsp;&nbsp;&nbsp;
    Embroidery&nbsp;<input name="serviceType[]" id="embroidery" type="checkbox" value="Embroidery" />&nbsp;&nbsp;&nbsp;&nbsp;
    Engraving&nbsp;<input name="serviceType[]" id="engrave" type="checkbox" value="Engraving" /><br/><br/>

    <input type="submit" />
</form>


Hm, that's strange.. It should show all the serviceType values seperated by \n, due to this line:

(is_array($_REQUEST['serviceType'])?implode("\n", $_REQUEST['serviceType']):$_REQUEST['serviceType'])

What if you change $_REQUEST to $_POST?


You can use foreach this way:

$serviceTypes = "";

if (is_array($_REQUEST['serviceType']))
{
    foreach ($_REQUEST['serviceType'] as $serviceType)
    {
        $serviceTypes.= "$serviceType\n";
    }
}

It's a possibility.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜