SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Calgary
    Posts
    222
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact Form "MINOR" Issue...

    Hi,

    I'm not sure if this falls as my own HTML form lack of knowledge or what not, but hopefully someone can point me in the right direction. I have a form that uses PHP and Javascript, and all works perfectly except for one thing.

    I want to have a section with multiple checkboxes and as many can be selected, although they are not required. However, what happens when I test and send this is it doesn't send both of the selected checkbox fields, it just sends one.

    I'm stumped, and I'm sure it's a problem with my code.

    Here is what I'm doing:

    Code:
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    														<tr>
    															<td width="208"><input id="goals" name="goals" type="checkbox" value="Weight Loss">
                                    							<label for="goals">Weight or Body Fat Loss </label></td>
    											  				<td width="147"><input id="goals" name="goals" type="checkbox" value="Increase Energy">
                                    							<label for="goals">Increase Energy </label></td>
    														</tr>
    														
    													</table>

    My PHP looks like this:

    Code:
    .(($_REQUEST['goals']) ? "Fitness Goals: ".$_REQUEST['goals']."\r\n" : "");

    I don't think the PHP is wrong I think it's how I've named the checkboxes or something. Come to think of it, this is likely no relation to JS...if not my apologies. I'm generally a designer/basic HTML/CSS coder...I'm not sure where I've got off on the wrong track though

  2. #2
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey man. I don't know ColdFusion. I do know some javascript & I am good with the flow of programming all together.(C++ Visual Basic, Some OpenGL) but anyway, I am pretty sure if you was to write the data anywhere I could see some complication issues dealing with the checkboxes. They are named the same. I cant read ColdFusion, but if what the ColdFusion code is doing is saving the data in the checkboxes??, then wouldnt it just send the data in the first goals checkbox?? My thinking is that it would go through your code and when it gets to the first 'goals' checkbox it would send that data. But then again, its hard for me to say cause I have absolutly 0 experience with .php. But my understanding of programing logic lead me to that conclusion, possibly?? Perhaps try renaming one of your checkboxes and changing that in your .php code. Just a thought. Sorry I cant be of more help.
    Good Luck!

    -crazedEggbeater

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2005
    Location
    London, UK
    Posts
    81
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't know how PHP deals with it but I hope it can create an array of it because there a multiple keys.
    However, you have an HTML error in that you use the id "goals" twice. Every id value has to be unique in the document. The name attribute can be repeated.

  4. #4
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow, the name attribute can be repeated? What if you had code like:

    document.goals.value = "blahblah" etc...
    how does it know which goals is the right one?? Just curious thanks.....

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If you repeat the name then it becomes an array so document.goals.value would be an invalid reference. You would need to use document.goals[0].value
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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