How to call a php function? [closed]

2019-03-07 06:50发布

how do I call this function to my html page I where I want the forms to appear?

<?php

function login_bar() {
  global $user;
  if ($user->uid == 0 ) {        
   $form = drupal_get_form('horizontal_login_block');
   return render($form);
  } else {
  // you can also integrate other module such as private message to show unread / read messages here
   return '<div id="loginbar"><p>' . t('Welcome back ') . ucwords($user->name) . '<p></div>';
  }
}

?>

2条回答
Root(大扎)
2楼-- · 2019-03-07 07:05

In form tag of your HTML page

<form type="post" action="test.php">

// test.php

<?php
function login_bar() {
}

// if you want to call the function on some button click

if(isset($_POST['submit']))
{
login_bar();
}
?>
查看更多
Root(大扎)
3楼-- · 2019-03-07 07:11

HTML page won`t process PHP call. Change your page to page.php and then call login_bar();

查看更多
登录 后发表回答