#415 How to prevent a custom "number field " can be negative ?

open
nobody
None
1
2013-11-14
2013-11-13
Hebus
No

I have made a custom field for how many visitors will be at the meeting.
Now they can choose a negative value of visitors, how can i prevent this?

gr. johan

Discussion

  • You can't in standard MRBS - you'll need to code it yourself. You can enforce it on the client side by using the HTML attribute min. This should be quite easy to do by modifying the function create_field_entry_custom_field() in edit_entry.php. If you're using the latest version in the trunk (Rev 2768 at the time of writing) then add something like

    if ($key == 'my_custom_field_name')
    {
      $params['attributes'][] = 'min="0"';
    }
    

    just after line 570. (I haven't tested this though)

    Ideally you'd also add some checks on the server side in edit_entry_handler.php for those using older browsers and in case users bypass the client side checks.

    I might think about incorporating a more generic version of this in standard MRBS.

    Campbell

     
    Last edit: Campbell Morrison 2013-11-13
  • Hebus
    Hebus
    2013-11-14

    Ty Campbell for the fast reply, i tested this (using the newest version downloaded from trunk) But it seems not to work . I used mediumint for this field.

    I could use $number = abs($number); before writing it into de db.
    But i cannot find where to put it. I'm not so good in php ;) .

     
  • How doesn't it work? Did you substitute your field name for 'my_custom_field_name'? What browser are you using?

    Campbell

     
  • Hebus
    Hebus
    2013-11-14

    Ok i'm oficialy the dumbest person in the world today.
    Forgot to add the field name afters the last edit i made .

    Bad idee to edit on 2 different scripts at once :s

    Ty Campbell it works :)

     


Anonymous


Cancel   Add attachments