Results 1 to 5 of 5

Thread: Creating db field with radio button or dropdown listbox

  1. #1
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Cool Creating db field with radio button or dropdown listbox

    You may want to add a new field that will allow user to choose one from two or more option. It could be yes / no answer or other option such as high / middle / top. You can display those options with radio buttom or dropdown listbox.

    The tutorial below is creating yes / no answer for credit card acceptance.

    First, you should create new field, just call it 'cc' which its type is int.
    admin cp -> database tables -> alter -> add

    Open add_form.html and modify_form.html, you must disable custom field autogenerate.
    delete <%custom_field_form%> or just put comment on it
    <!--<%custom_field_form%>-->

    Add radio buttom code:
    PHP Code:
    <tr>
      <
    td><font face="Arial" size="2">Credit Cards Accepted</font></td>
        <
    td>
        <
    input type=radio name=cc checked value="1">Yes &nbsp;&nbsp;&nbsp;
        <
    input type=radio name=cc value="0">No          
      
    </td>
    </
    tr
    Edit rows.html, new_link_rows.html, hot_link_rows.html, pick_link_rows.html, and top_rated_link_rows.html: add <%cc%> to display its value.

    Then you need to hack the php code a little. Open /lib/link.class.php
    You must edit Display() function, about line 1116 put the following code:
    PHP Code:
    if($cc=='0'$line str_replace("<%cc%>","Not Accept Credit Card",$line);
    elseif(
    $cc=='1'$line str_replace("<%cc%>","Accept Credit Card",$line); 
    It will replace 0 and 1 with other string. You can change the string to any others you wish.

    To have 3 or more states just put the option in template files and put the other elseif in /lib/link.class.php
    PHP Code:
    if($cc=='0'$line str_replace("<%cc%>","Not Accept Credit Card",$line);
    elseif(
    $cc=='1'$line str_replace("<%cc%>","Accept Credit Card",$line);
    elseif(
    $cc=='2'$line str_replace("<%cc%>","Unknown",$line); 

  2. #2
    Join Date
    Sep 2002
    Posts
    14

    Default Is that necessary?

    Hi,

    I only know enough php to modify existing code, but is it necessary to go through all those steps?

    Could you just have the cc field as type varchar or text, and include the value of the html field as the text string that you want in the end instead of using an integer and then substituting a text string for the integer?

    ex.

    PHP Code:
    <tr>
      <
    td><font face="Arial" size="2">Credit Cards Accepted</font></td>
        <
    td>
        <
    input type=radio name=cc checked value="Accept credit card">Yes &nbsp;&nbsp;&nbsp;
        <
    input type=radio name=cc value="Not accept credit card">No          
      
    </td>
    </
    tr

  3. #3
    Join Date
    Aug 2002
    Location
    Germany
    Posts
    1,180

    Default check box control ?

    Hello,

    thats what Im searching for !
    But one more question:
    If I take Dodys ceckbox, how can I control, that the user checked the box before adding his link ?

    I want to hvae a checkbox that the user accept the rules of my directory - if he don't accept, he can't post the link.
    Display that field is not important, it is enough, that it is in the data base and the user must check the box.

    Some more tipps ?

    Greetings
    Frank

  4. #4
    Join Date
    Aug 2001
    Location
    Indonesia
    Posts
    3,732

    Default

    Frank, this may no longer work or too much working. I'll write a tech note how to do this soon

  5. #5
    Join Date
    Aug 2002
    Location
    Germany
    Posts
    1,180

    Default checkboxes and more

    Hello Dody,

    Do you think on a small tutorial how to integrate checkboxes and a combination of checkbox and display of text and images ?

    This will be great !!

    Check boxes a user must check !
    Check box that display textes and images like "Do you speak german ?" -> images or text in the link view...

    Greetings
    Frank

Similar Threads

  1. Using Radio Button and Drop Down Menu in Custom Field
    By dody in forum Tutorials, Hints & Tips
    Replies: 2
    Last Post: 12-20-2003, 10:58 PM
  2. Creating field with radio button
    By bkmdano in forum v5.x
    Replies: 22
    Last Post: 04-07-2002, 03:09 PM

Posting Permissions

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