PHP Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tphamrick
Forum Newbie
Posts: 1
Joined: Tue Jan 18, 2011 6:31 pm

PHP Form

Post by tphamrick »

I'm creating a wordpress template that will have a menu with settings for look and layout of the site. One of the settings is having a way to change the header of the site, either have text or an image. I want to have two options with radio buttons, one for "Text" and one for "Image." I know how to create the form and get it to callout to the sites header. What I am having a problem with is, I want the "Text" option to be the default setting. Then the user can click the "Image" radio button to upload a custom header image. What I need help with, I guess, is the use of "if" and "else" commands. When one radio button is selected there is an output to the header, then when the other radio button is selected something different is outputed to the header.

Here is the base form code I have. I have tried different commands and can not seem to get it to work.

Code: Select all

<?php settings_fields('bpt-settings-group'); ?>
<table class="form-table">
    	<tr valign="top">
        	<th scope="row"><input type="radio" name="Header Type" value="Text" />Header Text:</th>
        	<td><textarea style="width:50em; height: 27px;" name="header_text"><?php echo get_option('header_text'); ?></textarea></td>
        </tr>
        <tr valign="top">
        	<th scope="row"><input type="radio" name="Header Type" value="Image" />Header Image:</th>
            <td><textarea style="width:50em; height:27px;" name="header_image"><?php echo get_option('header_image'); ?></textarea></td>
        </tr>
</table>
I know know the "Image" selection isn't an upload form. I have that made already that will be pasted into this code once I get the radio buttons to work right.
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: PHP Form

Post by Peter Kelly »

Code: Select all

<?php settings_fields('bpt-settings-group'); ?>
<table class="form-table">
        <tr valign="top">
                <th scope="row"><input type="radio" name="Header Type" value="Text" checked />Header Text:</th>
                <td><textarea style="width:50em; height: 27px;" name="header_text"><?php echo get_option('header_text'); ?></textarea></td>
        </tr>
        <tr valign="top">
                <th scope="row"><input type="radio" name="Header Type" value="Image" />Header Image:</th>
            <td><textarea style="width:50em; height:27px;" name="header_image"><?php echo get_option('header_image'); ?></textarea></td>
        </tr>
</table>
Placing the checked attribute inside an input makes it checked or selected, But you might want to run a if statement to check which one is actually selected in the database or what ever?
Post Reply