1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help with php form code

Discussion in 'PHP' started by macstux, Dec 21, 2015.

  1. #1
    Hello DPs,

    I need some help with my PHP form. I am trying to make a form that submits to my email but also, if they check naughty or nice checkbox they will be redirected to either naughty or nice whichever one they choose. Though I keep getting an error message when i click submit.

    My index.php
    http://pastebin.com/jEWzFVZL

    send.php
    http://pastebin.com/vgcx6FnH

    Cant wait to here your input, and learn a little more!
     
    macstux, Dec 21, 2015 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Okay. First things first: throw away that code, and start over. You have so many things wrong in that index-file that it hurts my eyes. Tables for form-layout? Really? No proper structure either - they´re called "labels" - look it up.
    Since you´re not saying what kind of error you´re getting, it´s almost impossible to help - but for the redirect, you´re not actually redirecting, you´re echoing out stuff - I´m not sure if that´s intentional or not?
     
    PoPSiCLe, Dec 21, 2015 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    @PoPSiCLe has it right, the HTML for that ALONE screams "I don't know what a form is" as you've got no labels, no fieldsets, and WORSE that's not tables for layout, that's tables for NOTHING!!! If there's only TD, and there's only one TD per TR, there is NO reason to EVER use a table!!!

    Though your REAL problem? In your markup you have these two input:

    <input type="checkbox" name="list[]" value="Naughty">
    <input type="checkbox" name="list[]" value="Nice">

    You seem to be trying to access those as:
    $_POST['checkbox']

    When those would not make a $_POST['checkbox'], they'd be making $_POST['list']...

    To get what you want server-side those input should be:
    <input type="checkbox" name="checkbox[Naughty]">
    <input type="checkbox" name="checkbox[Nice]">

    They don't even actually need a value as they will either exist or not exist in the resulting $_POST['checkbox'] array.
     
    deathshadow, Dec 22, 2015 IP
    KangBroke likes this.
  4. macstux

    macstux Well-Known Member

    Messages:
    336
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    155
    #4
    Oh wow, my bad didnt mean to offend you. Ill jjst throw it away and retry i guess, i just didnt want to use someone elses work for a form, was trying to create my own.

    This was the error i was getting
    "Parse error: syntax error, unexpected T_STRING in /hermes/bosweb26b/b1807/ipg.stmcevoy/Santa/send.php on line 23"
     
    macstux, Dec 22, 2015 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    The guy had a specific question so instead of answering it we berate his experience and his attempt at learning then go on an offbeat tangent about the validation of his HTML code because it isn't up to standard or your standards????? Try answering his question first then if you want to assist him with his HTML code then do so maturely.
     
    Last edited by a moderator: Dec 23, 2015
    NetStar, Dec 22, 2015 IP
    KangBroke likes this.
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    First off, @macstux, you didn't offend -- it's just we see the same mistakes over and over and over again -- through faulty learning, through blind copypasta of other people's works, and because a lot of the people teaching and writing tutorials really have zero business doing so.

    We all start somewhere, I was writing code like what you have now back in '98 before I took the time to understand what HTML is, what it is for, and what the tags MEAN.
     
    Last edited by a moderator: Dec 23, 2015
    deathshadow, Dec 22, 2015 IP
    KangBroke likes this.
  7. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #7
    @deathshadow can be a bit harsh sometimes but at the same time you gotta see it for what it is. If you go to a mechanics forum and say some thing stupid they would ridicule you the same. Outdated code should be shunned. I do think that sometimes text can appear insulting but it is really taken out of context. Typing something and saying something can come out completely different. In most cases such as this one he actually did tell the OP ways to accomplish the goal after the supposed hate talk.

    I too have felt insulted by deathshadow before when I did something stupid. But that just means that he cares :p. If he did not care he would just encourage bafoonery.
     
    KangBroke, Dec 23, 2015 IP