Preventing form items from being sent to the server

Discussion in 'PHP' started by enchance, Oct 3, 2009.

  1. #1
    Usually, when clicking on a 'submit' button, the form sends all the 'value' attributes within the form to the server. But is there a way to not send the 'value' attribute of form elements which are invisible (style="display:none")? :rolleyes:
     
    enchance, Oct 3, 2009 IP
  2. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #2
    I don't know of any way to do this, but I have a suggestion:

    It sounds like you're using some dynamic content. Instead of hiding a field if you don't need it, just don't generate that field when you draw the form.
     
    goliath, Oct 3, 2009 IP
  3. ziya

    ziya Well-Known Member

    Messages:
    1,971
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Why do you need , not to send the value ?
     
    ziya, Oct 3, 2009 IP
  4. renownedmedia

    renownedmedia Well-Known Member

    Messages:
    65
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #4
    Include another fields which tells the server what your form is doing and have the server decide which information to ignore.
     
    renownedmedia, Oct 3, 2009 IP
  5. enchance

    enchance Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I guess I'll just use AJAX then. That way it only generates the form items it needs. I just thought there might be a way to disregard items which are not visible on the page. Thanks for the help.
     
    enchance, Oct 3, 2009 IP
  6. enchance

    enchance Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I got it and the answers pretty simple too! Just add disabled="disabled" to the item and it won't be sent along with $_POST. How ironic that I was thinking of using AJAX or PHP when HTML could already do the trick for me. This proves that the right answer we're looking for is sometimes just under our noses. :D

    Thanks everyone!
     
    enchance, Oct 3, 2009 IP