MyBB Community Forums

Full Version: Password Generator Plugin - Template Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok, so I'm making a password generator plugin that lets users generate passwords when they want, but I am a bit stuck as to what to do now:

function password_generator_activate() {
    global $db;
    $template = "
<body>
  <div>
    <p>Click the following button to generate a password:</p>
    <p><input type='submit' id='ircher_button_generate_password' value='Generate Password' /></p>
    <p>Generated Password: <strong>{$password_generator}</strong></p>
  </div>
</body>
</html>";

    $template_insert_array = array(
      'title' => 'ircher_password_generator_template',
      'template' => $db->escape_string($template),
      'sid' => '-1',
      'version' => '1.0',
      'dateline' => time()
    );
    $db->insert_query('templates', $template_insert_array);
}

function password_generator_page() {
    global $mybb, $templates, $lang, $header, $headerinclude, $footer;
    if ($mybb->get_input( 'action', MyBB::INPUT_STRING) == 'password_generator_view') {
      add_breadcrumb( 'Password Generator', "misc.php?action=password_generator_view");
      $password_generator = '';
      eval( '$sections = "'.$templates->get( 'ircher_password_generator_template').'";');
      eval( "\$page = \"".$templates->get('misc_help')."\";");
      output_page( $page );
}

Few questions:

1. How do I execute a function I create when the button is pressed
2. What would be the simplest way for me to link to the page
3. How do I fix it where the header info is what I want, but consistent with other pages? (In the second eval, I tried copy/paste template markup from the default to the template and eval my template, but that didn't seem to work....)
Quote:1. How do I execute a function I create when the button is pressed

Use either the jQuery library which is built in or standard javascript. Look up DOM Events or Mouse Events.
(2015-02-16, 05:49 PM)dragonexpert Wrote: [ -> ]
Quote:1. How do I execute a function I create when the button is pressed

Use either the jQuery library which is built in or standard javascript. Look up DOM Events or Mouse Events.

I know about dom events, but I'd rather use a custom php function because I can use some of the string function like explode(), implode(), and other functins which randomize values. Would implementing a form element work (I was hoping not to have to implement one though).

I cannot seem to get variable substitution to work? How do you substitute variables in templates? I looked at the doc, but it isn't working.