滚动到id PHP功能

时间:2014-06-04 19:52:23

标签: php

我有一个表单,在提交时刷新页面并显示错误。我只需要它滚动回到表单。这是表单标记:

<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>

这是功能:

function GetSelfScript()
{
    return htmlentities($_SERVER['PHP_SELF']);
}

如何将#contact添加到函数中?

谢谢!

1 个答案:

答案 0 :(得分:0)

你不需要这里的PHP。将要跳转的元素的id作为锚点附加到操作字段。

e.g。

<form id="contactUs" action="target.php#contactUs" />

在你的情况下(无论是什么适当的)

<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>#contactus' method='post' accept-charset='UTF-8'>

function GetSelfScript($anchor = null)
{
    $anchor = $anchor === null ? '' : '#' . $anchor;
    return htmlentities($_SERVER['PHP_SELF']) . '#' . $anchor;
}

<form id='contactus' action='<?php echo $formproc->GetSelfScript("contactus"); ?>#contactus' method='post' accept-charset='UTF-8'>