Welcome to Geeklog, Anonymous Saturday, December 21 2024 @ 09:27 pm EST

Geeklog Forums

Radio Buttons in lib-custom.php


HELP!

Anonymous
I'm trying to add a set of radio buttons to my site, and I'm stumped. HTML radio buttons are no problem, but I'm not proficient in PHP.

I do have a drop down menu working. It pulls the info from a table to display, and then saves it to the user_custom table. It then shows the selected field when the user comes back to edit it later. I'd like for the radio buttons to do the same, but for some reason, all I've been able to do is get the radio buttons to show up.

I realize that I may not get a response, but after working on this for a week straight, I'm about to quit. Can someone throw me a bone?
 Quote

Earnest

Anonymous
There may be better ways to do this than what I am about to show, but this works for me.

You'll probably want to set this up with some "if" statements if you are reading a saved value and want the status reflected. So it might look like this:

Text Formatted Code
if($the_field_name_we_took_from_a_table == "A") {
       $retval .= '<INPUT TYPE=radio NAME="field_name" value="A" CHECKED> Option A<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="B"> Option B<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="C"> OPtion C<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="D"> Option D<BR>';
} elseif ($the_field_name_we_took_from_a_table == "B") {
       $retval .= '<INPUT TYPE=radio NAME="field_name" value="A"> Option A<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="B" CHECKED> Option B<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="C"> OPtion C<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="D"> Option D<BR>';
} elseif ($the_field_name_we_took_from_a_table == "C") {
       $retval .= '<INPUT TYPE=radio NAME="field_name" value="A"> Option A<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="B"> Option B<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="C" CHECKED> OPtion C<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="D"> Option D<BR>';
} elseif ($the_field_name_we_took_from_a_table == "C") {
       $retval .= '<INPUT TYPE=radio NAME="field_name" value="A"> Option A<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="B"> Option B<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="C"> OPtion C<BR>
            <INPUT TYPE=radio NAME="field_name" VALUE="D"  CHECKED> Option D<BR>';
}


Hope this helps

-E
 Quote

HELP!

Anonymous
Thanks Earnest, I appreciate your help.

One problem I've run into is the fact when I add some code to the CUSTOM_userEdit function in lib-custom.php, only a blank screen is returned. No error message, no entry in error.log, nothing. I'm not able to figure out where I went wrong. I'd be able to figure something out if I had an idea of where look, but I get nothing. It will be sitewide too.

Ok, here's where I'm at, I took your example, added the components I'm trying to get, and I get the blank screen I mentioned above.

Text Formatted Code

$marital_status = DB_getitem($_TABLES['user_custom'], 'maritalstatus', $uid);
     
     if($marital_status == "Single") {
       $retval .= '
            <INPUT TYPE=radio NAME="field_name" value="Single" CHECKED> Single
            <INPUT TYPE=radio NAME="field_name" VALUE="Married"> Married
            <INPUT TYPE=radio NAME="field_name" VALUE="Divorced"> Divorced
            <INPUT TYPE=radio NAME="field_name" VALUE="Widowed"> Widowed';
        } elseif ($marital_status == "Married") {
       $retval .= '
            <INPUT TYPE=radio NAME="field_name" value="Single"> Single
            <INPUT TYPE=radio NAME="field_name" VALUE="Married" CHECKED> Married
            <INPUT TYPE=radio NAME="field_name" VALUE="Divorced"> Divorced
            <INPUT TYPE=radio NAME="field_name" VALUE="Widowed"> Widowed';
        } elseif ($marital_status == "Divorced") {
       $retval .= '
            <INPUT TYPE=radio NAME="field_name" value="Single"> Single
            <INPUT TYPE=radio NAME="field_name" VALUE="Married"> Married
            <INPUT TYPE=radio NAME="field_name" VALUE="Divorced" CHECKED> Divorced
            <INPUT TYPE=radio NAME="field_name" VALUE="Widowed"> Widowed';
        } elseif ($marital_status == "Widowed") {
       $retval .= '
            <INPUT TYPE=radio NAME="field_name" value="Single"> Single
            <INPUT TYPE=radio NAME="field_name" VALUE="Married"> Married
            <INPUT TYPE=radio NAME="field_name" VALUE="Divorced"> Divorced
            <INPUT TYPE=radio NAME="field_name" VALUE="Widowed" CHECKED> Widowed';
        }

    DB_query("UPDATE {$_TABLES['user_custom']} SET maritalstatus = '{$_POST['marital_status']}' WHERE uid = $uid");
 


Like I said in my first post, I'm not proficient in PHP, so without having an error message telling me where to look, I'm lost.

Thanks again for your help.
 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote by: HELP!

One problem I've run into is the fact when I add some code to the CUSTOM_userEdit function in lib-custom.php, only a blank screen is returned. No error message, no entry in error.log, nothing.

This means the PHP interpreter found an error in your code and aborted the page. Comment out your changes and reintroduce those changes a few lines at a time until you find the line the error is on. Usually it means you forgot a closing parenthesis or have an extra brace. Something stupid which you end up spending an hour hunting for.

Alternatively, add this code above and below your code:
Text Formatted Code

error_reporting(E_ALL);
ini_set('display_errors','On');

// your code

error_reporting( E_ERROR | E_WARNING | E_PARSE | E_COMPILE_ERROR );
 

That will sometimes flush out errors as well. Remember to remove these lines of code when you are done making code changes.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
:rtfm: Also see Blank page
 Quote

HELP!

Anonymous
Thanks Dirk, jmucchiello, and Earnest. Dirk's suggestion did the trick. Hunting down a missing bracket just got a lot easier. jmucchiello, I tried adding your code as you suggested, but still got the blank page.

It works just fine now though, so thanks again guys.
 Quote

HELP!

Anonymous
In case anyone else needs this, here is the code I have. It works for me.

I have it under CUSTOM_userEdit:

Text Formatted Code

     //  Radio Buttons
        $marital_status = DB_getitem($_TABLES['user_custom'], 'maritalstatus', $uid);
           
        if ($marital_status == "") {
                $retval .= '
                <tr>
                <td width="100px"><label for="marital_status">Marital Status:</label></td>
                <td>
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Single"> Single
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Married"> Married
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Divorced"> Divorced
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Widowed"> Widowed
                </tr>';
        } elseif ($marital_status == "Single") {
                $retval .= '
                <tr>
                <td width="100px"><label for="marital_status">Marital Status:</label></td>
                <td>
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Single" CHECKED> Single
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Married"> Married
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Divorced"> Divorced
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Widowed"> Widowed
                </tr>';
        } elseif ($marital_status == "Married") {
                $retval .= '
                <tr>
                <td width="100px"><label for="marital_status">Marital Status:</label></td>
                <td>
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Single"> Single
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Married" CHECKED> Married
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Divorced"> Divorced
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Widowed"> Widowed
                </tr>';
        } elseif ($marital_status == "Divorced") {
                $retval .= '
                <tr>
                <td width="100px"><label for="marital_status">Marital Status:</label></td>
                <td>
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Single"> Single
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Married"> Married
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Divorced" CHECKED> Divorced
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Widowed"> Widowed
                </tr>';
        } elseif ($marital_status == "Widowed") {
                $retval .= '
                <tr>
                <td width="100px"><label for="marital_status">Marital Status:</label></td>
                <td>
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Single"> Single
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Married"> Married
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Divorced"> Divorced
                        <INPUT TYPE=radio NAME="marital_status" VALUE="Widowed" CHECKED> Widowed
                </tr>';
        }

 


And this goes under CUSTOM_userSave:

Text Formatted Code


    DB_query("UPDATE {$_TABLES['user_custom']} SET maritalstatus = '{$_POST['marital_status']}' WHERE uid = $uid");

 

 Quote

Status: offline

jmucchiello

Forum User
Full Member
Registered: 08/29/05
Posts: 985
Quote by: HELP!


Text Formatted Code


    DB_query("UPDATE {$_TABLES['user_custom']} SET maritalstatus = '{$_POST['marital_status']}' WHERE uid = $uid");

 


Never trust data submitted to your code from a browser. Ever. Forms can be faked.
Text Formatted Code

   $marital_status = isset($_POST['marital_status']) ? addslashes(COM_applyFilter($_POST['marital_status'])) : '';
   DB_query("UPDATE {$_TABLES['user_custom']} SET maritalstatus = '{$marital_status}' WHERE uid = $uid");
 
 Quote

All times are EST. The time is now 09:27 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content