how to NOT send a variable unless something is entered in the field

Discussion in 'PHP' started by marcnyc, Jun 27, 2009.

  1. #1
    Hello, I am working with a form which has a lot of text fields which submits some data via POST. I would like some of this data to ONLY be sent if the user actually has entered something in the textfield, and if the user didn't I would like that variable not to even be sent via POST (not even an empty value)... Is this possible somehow?
    Thanks
     
    marcnyc, Jun 27, 2009 IP
  2. kingdan221

    kingdan221 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That's a client-side work (hint: javascript)
    PHP validation is made upon submit.
     
    kingdan221, Jun 27, 2009 IP
  3. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I guess I'll have to repost in the JS section then
     
    marcnyc, Jun 27, 2009 IP
  4. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    so there is no PHP command to tell the compiler not to even consider empty fields when (before) submitting?
     
    marcnyc, Jun 27, 2009 IP
  5. kingdan221

    kingdan221 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No, JS is the solution for such thing.
     
    kingdan221, Jun 28, 2009 IP
  6. wd_2k6

    wd_2k6 Peon

    Messages:
    1,740
    Likes Received:
    54
    Best Answers:
    0
    Trophy Points:
    0
    #6
    But are you still allowing the form to be sent even if a user has entered nothing in a field, cause you could check whether a value exsits after the form is submitted via isset or isempty i think
     
    wd_2k6, Jun 28, 2009 IP
  7. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    In there lays the problem... unfortunately it appears that this form is so big that it is not even sent... If it were being sent I would then process $_POST with isset() or empty() but it not even being sent in the first place ($_POST is empty), which is why I want to trim down what is being sent to the minimum so that it actually is sent, you know?
     
    marcnyc, Jun 28, 2009 IP
  8. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Somebody told me that disabled form elements aren't sent and offered this code:


    however it doesn't work... am I going in the right direction?
     
    marcnyc, Jun 28, 2009 IP
  9. IMaster

    IMaster Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    you can do it with javascript
     
    IMaster, Jun 28, 2009 IP
  10. HivelocityDD

    HivelocityDD Peon

    Messages:
    179
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Make use of some javascript form handling scripts which checks invalid input boxes.
     
    HivelocityDD, Jun 28, 2009 IP
  11. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    could you provide an example? I know how to check for input in fields with JS but I am not sure how to disable fields to make them not being sent at all
     
    marcnyc, Jun 28, 2009 IP
  12. kingdan221

    kingdan221 Peon

    Messages:
    84
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Remove them using Javascript DOM [hint: removechild]
     
    kingdan221, Jun 29, 2009 IP
  13. marcnyc

    marcnyc Peon

    Messages:
    70
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    thanks for your post
     
    marcnyc, Jun 30, 2009 IP
  14. SunstarShop

    SunstarShop Peon

    Messages:
    582
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Yeah, i think before you submit the form you should disable the fileds with javascript!
     
    SunstarShop, Jul 1, 2009 IP