html - I need to use a PHP variable between functions -


need options page wp plugin, user can remove link choosing dropdown.

the options page created , variable set in function called printselection(). function returns value in dropdown box wp dashboard.

function printselection() { if(isset($_post['selectbox'])){     return $_post['selectbox']; } }  $link = printselection(); print($link); 

the $link variable being printed wp options page. use variable in frontend well, after form. full code here:

<?php /* plugin name: gladstone brookes mortgage calculator widget plugin uri: http://gladstonebrookesmortgages.co.uk description: simple mortgage calculator widget version: 1.0 author: ian butler author uri: http://gladstonebrookesmortgages.co.uk */  /*-----------------------------------------------------------------------------------*/ /* include css */ /*-----------------------------------------------------------------------------------*/  function gb_mortgage_calculator_css() {      wp_enqueue_style( 'gb_mortgage_calculator', plugins_url( 'assets/style.css',  __file__ ), false, '1.0' ); } add_action( 'wp_print_styles', 'gb_mortgage_calculator_css' );  /*-----------------------------------------------------------------------------------*/ /* include js */ /*-----------------------------------------------------------------------------------*/  function gb_mortgage_calculator_scripts() { wp_enqueue_script( 'calc', plugins_url( 'assets/calculator.js', __file__ ),  array('jquery'), '1.0', true ); } add_action( 'wp_enqueue_scripts', 'gb_mortgage_calculator_scripts' );  /*-----------------------------------------------------------------------------------*/ /* register widget */ /*-----------------------------------------------------------------------------------*/  class gb_mortgage_calculator extends wp_widget {  function gb_mortgage_calculator() {    $widget_ops = array('description' => 'display mortgage calculator.' );    parent::wp_widget(false, __('gb mortgage calculator', 'gladstonebrookes'),$widget_ops);       }  function widget($args, $instance) {           extract( $args );         $title = $instance['title'];       echo $before_widget;      if ($title) { echo $before_title . $title . $after_title; }         global $ct_options;     ?>  <div id="calculator" class="grid-60 prefix-15 suffix-15">         <form name="mortgagecalculator" id="mortgagecalculator">     <label class="grid-60">loan amount (£):</label><input class="grid-40"  id="la" type="text" name="la" value="0" />     <label class="grid-60">interest rate (%):</label><input class="grid-40" id="ir" type="text" name="ir" value="0" />     <label class="grid-60">mortgage term (years):</label><input class="grid-40" id="mt" type="text" name="term" value="0" />     <select id="type"><option id="r" value="repayment">repayment</option> <option id="io" value="interestonly">interest only</option></select>&nbsp;     <input onclick="checkforzero(this); calculatepayment(this)" type="button" name="cmdcalc" value="calculate" />     <input onclick="resetform(this)" type="button" name="reset" value="clear form" />     <label class="grid-60 bold">total repayable:</label><input class="grid-40  bold" id="payments" type="text" name="payments" />     <label class="grid-60 bold">monthly payments:</label><input class="grid-40 bold" id="pmt" type="text" name="pmt" /> </form> <p><?php echo $link ?></p> </div>  <div id="overlay" onclick="modal(this)"> <h4>please enter numeric values only</h4> <h4>the value of following fields cannot zero:</h4> <p><strong>loan amount</strong></p><p><strong>interest rate</strong></p> <p><strong>mortgage term</strong></p> <p style="text-decoration:underline; color:blue;">dismiss</p> </div>  <div id="fade"></div>  <?php echo $after_widget; ?>    <?php }  function update($new_instance, $old_instance) {      return $new_instance; }  function form($instance) {          $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';  ?>     <p>        <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('title:','gladstonebrookes'); ?></label>        <input type="text" name="<?php echo $this->get_field_name('title'); ?>"  value="<?php echo $title; ?>" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" />     </p>     <?php } }   add_action( 'widgets_init', create_function( '', 'register_widget("gb_mortgage_calculator");' ) );  /*-----------------------------------------------------------------------------------*/ /* register shortcode */ /*-----------------------------------------------------------------------------------*/  function gb_mortgage_calculator_shortcode($atts) {  ?>     <div class="clear"></div>  <div id="calculator" class="grid-60 prefix-15 suffix-15"> <h2>mortgage calculator</h2>         <form name="mortgagecalculator" id="mortgagecalculator">     <label class="grid-60">loan amount (£):</label><input class="grid-40" id="la" type="text" name="la" value="0" />     <label class="grid-60">interest rate (%):</label><input class="grid-40" id="ir" type="text" name="ir" value="0" />     <label class="grid-60">mortgage term (years):</label><input class="grid-40" id="mt" type="text" name="term" value="0" />     <select id="type"><option id="r" value="repayment">repayment</option>     <option id="io" value="interestonly">interest only</option></select>&nbsp;     <input onclick="checkforzero(this); calculatepayment(this)" type="button" name="cmdcalc" value="calculate" />     <input onclick="resetform(this)" type="button" name="reset" value="clear form" />     <label class="grid-60 bold">total repayable:</label><input class="grid-40 bold" id="payments" type="text" name="payments" />     <label class="grid-60 bold">monthly payments:</label><input class="grid-40 bold" id="pmt" type="text" name="pmt" /> </form> <p><?php echo $link ?></p> </div>  <div id="overlay" onclick="modal(this)"> <h4>please enter numeric values only</h4><h4>the value of following fields cannot zero:</h4> <p><strong>loan amount</strong></p><p><strong>interest rate</strong></p> <p><strong>mortgage term</strong></p> <p style="text-decoration:underline; color:blue;">dismiss</p> </div>  <div id="fade"></div>  <?php } add_shortcode('mortgage_calculator', 'gb_mortgage_calculator_shortcode');  add_action('admin_menu', 'create_menu');   /*-----------------------------------------------------------------------------------*/ /* create options page */ /*-----------------------------------------------------------------------------------*/   function create_menu (){  add_management_page('gb mortgage calculator', 'gb mortgage calculator', 10, 'gbmc_setting_file', 'gbmc_setting');  }  function gbmc_setting() { ?>  <div class="wrap">  <form method="post" name="options" target="_self">      <h2>display link</h2>      <table width="100%" cellpadding="10" class="form-table">      <tr>     <td align="left" scope="row">          <label>display link</label>         <select name="selectbox">             <option value='<a href="http://gladstonebrookesmortgages.co.uk">powered gladstone brookes mortgages</a>'>block</option>             <option value="">hide</option>         </select>       </td>      </tr>      </table>     <p class="submit">      <input type="submit" name="submit" value="update" />      </p>  </form>  </div>  <?php } function printselection() { if(isset($_post['selectbox'])){     return $_post['selectbox']; } }  $link = printselection(); print($link);  ?> 

it seems have exhausted every option still can't work. prefer not use globals either. in advance!

i think problem is, call function @ end of file , after declare variable. should call printselection() @ beginning of file , after assign return $link. should solve it


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -