WordPress Plugin Help database storing / retrieving value

Discussion in 'Programming' started by muiomuio, Aug 23, 2008.

  1. #1
    I'm a newbie programmer and I am trying to develop a wordpress plugin.

    I have created an admin panel and set the text field and submit button. My problem is adding and retrieving the value from the data base.

    Here is the Form:

    
    function mms_form () {
    	
    	$default_value = get_option('default_size');
    	global $default_value;
    	
    	if(empty($default_size)) {
    		add_option('default_size',50,'short url','');
    		}
    	else {
    	$default_size = get_option('default_size');
    	}
    
    	?>
        <form method="post" style="width:60%; margin: 5% auto;">
        	<label for="chunk_size">URL Size:
            	<input type="text" name="chunk_size" value="<?=$default_size ?>" />
            </label><br />
            <input type="submit" name="submit" value="Submit" />
    	</form>
        <?php
    }
    
    Code (markup):
    Here is the options update:

    
    function update_mms_options() {
    	$ok = false;
    	
    	//input validation
    	if($_REQUEST['chunk_size']) {
    		update_option('default_size', $_REQUEST['chunk_size']);
    		$ok = true;
    	}
    	
    	if($ok) {
    		?><div id="message" class="updated fade">
            	<p>Settings Updated</p>
              </div><?php
    	}
    	else {
    		?><div id="message" class="error fade">
            	<p>Captain, Captain an error has occured</p>
              </div><?php
    	}
    } // update_mms_options
    
    Code (markup):
    The text field isn't sending nor retriving the #default_size value.

    Can anyone help me out here?

    thanks :cool:
     
    muiomuio, Aug 23, 2008 IP