权限没有,则隐藏 function forum_list_access_filter($forumlist, $gid, $allow = 'allowread') { global $grouplist; if (empty($forumlist)) return array(); if (1 == $gid) return $forumlist; $forumlist_filter = $forumlist; $group = $grouplist[$gid]; foreach ($forumlist_filter as $fid => $forum) { if (empty($forum['accesson']) && empty($group[$allow]) || !empty($forum['accesson']) && empty($forum['accesslist'][$gid][$allow])) { unset($forumlist_filter[$fid]); } unset($forumlist_filter[$fid]['accesslist']); } return $forumlist_filter; } function forum_filter_moduid($moduids) { $moduids = trim($moduids); if (empty($moduids)) return ''; $arr = explode(',', $moduids); $r = array(); foreach ($arr as $_uid) { $_uid = intval($_uid); $_user = user_read($_uid); if (empty($_user)) continue; if ($_user['gid'] > 4) continue; $r[] = $_uid; } return implode(',', $r); } function forum_safe_info($forum) { //unset($forum['moduids']); return $forum; } function forum_filter($forumlist) { foreach ($forumlist as &$val) { unset($val['brief'], $val['announcement'], $val['seo_title'], $val['seo_keywords'], $val['create_date_fmt'], $val['icon_url'], $val['modlist']); } return $forumlist; } function forum_format_url($forum) { global $conf; if (0 == $forum['category']) { // 列表URL $url = url('list-' . $forum['fid'], '', FALSE); } elseif (1 == $forum['category']) { // 频道 $url = url('category-' . $forum['fid'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = url('read-' . trim($forum['brief']), '', FALSE); } if ($conf['url_rewrite_on'] > 1 && $forum['well_alias']) { if (0 == $forum['category'] || 1 == $forum['category']) { $url = url($forum['well_alias'], '', FALSE); } elseif (2 == $forum['category']) { // 单页 $url = ($forum['threads'] && $forum['brief']) ? url($forum['well_alias'] . '-' . trim($forum['brief']), '', FALSE) : url($forum['well_alias'], '', FALSE); } } return $url; } function well_forum_alias() { $forumlist = forum_list_cache(); if (empty($forumlist)) return ''; $key = 'forum-alias'; static $cache = array(); if (isset($cache[$key])) return $cache[$key]; $cache[$key] = array(); foreach ($forumlist as $val) { if ($val['well_alias']) $cache[$key][$val['fid']] = $val['well_alias']; } return array_flip($cache[$key]); } function well_forum_alias_cache() { global $conf; $key = 'forum-alias-cache'; static $cache = array(); // 用静态变量只能在当前 request 生命周期缓存,跨进程需要再加一层缓存:redis/memcached/xcache/apc if (isset($cache[$key])) return $cache[$key]; if ('mysql' == $conf['cache']['type']) { $arr = well_forum_alias(); } else { $arr = cache_get($key); if (NULL === $arr) { $arr = well_forum_alias(); !empty($arr) AND cache_set($key, $arr); } } $cache[$key] = empty($arr) ? '' : $arr; return $cache[$key]; } ?>php - Javascript autosubmit form - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Javascript autosubmit form - Stack Overflow

programmeradmin10浏览0评论

I have a form that I need to submit automatically... (the fields are already filled and its plicated to explain why but it IS necessary to do it this way).. I know how to autosubmit the form using Javascript but the only problem I have is that there is more than 1 submit button.. and I need 1 in particular to be submitted... thanks in advance

EDIT2(source):

<I put the javascript in the head... />
<FORM ACTION="PDF.php" name="form" METHOD="post">
<A whole bunch of inputs />
<INPUT TYPE="submit" name="form-save" VALUE="Save Changes" >
<INPUT TYPE="submit" name="form-submit" VALUE="Submit" >
<input type="submit" name="print" id="print" value="Download PDF" />
</form>

I have a form that I need to submit automatically... (the fields are already filled and its plicated to explain why but it IS necessary to do it this way).. I know how to autosubmit the form using Javascript but the only problem I have is that there is more than 1 submit button.. and I need 1 in particular to be submitted... thanks in advance

EDIT2(source):

<I put the javascript in the head... />
<FORM ACTION="PDF.php" name="form" METHOD="post">
<A whole bunch of inputs />
<INPUT TYPE="submit" name="form-save" VALUE="Save Changes" >
<INPUT TYPE="submit" name="form-submit" VALUE="Submit" >
<input type="submit" name="print" id="print" value="Download PDF" />
</form>
Share Improve this question edited Jun 23, 2010 at 18:15 Sean Vieira 160k34 gold badges320 silver badges296 bronze badges asked Jun 23, 2010 at 15:07 Luke3butlerLuke3butler 2102 silver badges13 bronze badges 1
  • 1 You really should explain why you think you need to auto-submit a form, because usually it's a sign of using the wrong technology to solve the wrong problem. Hint: What about users without JS? – RoToRa Commented Jun 23, 2010 at 15:10
Add a ment  | 

4 Answers 4

Reset to default 4

instead of going for a click event on a submit button, you can call submit of a form object from javascript.

Example :

<head>
<title>Auto Submit Form</title>
<script type="text/javascript">
    window.onload = function () {
        var form = document.getElementById("PDFGenerationForm");
        form.submit();
    };

    function OnFormSubmit() {
        alert("Submitting form.");
    }
</script>

<body>
<form id="PDFGenerationForm" action="" method="post" onsubmit="OnFormSubmit">
    <!--Any input tags go in here-->
</form>

This editor won't let me paste the whole HTML in here. So, it is in fragments.

$("#yourbuttonid").click();

EDIT:

<form>
    ... 
   <input type="submit" id="myFirstsubmit" /> 
   <input type="submit" id="mysubmit" /> 
</form> 
<script type="text/javascript">  
    $(document).ready(function(){$("#mysubmit").click();}); 
</script>

If you really want to click a specific button, add this script to the end of your page:

<script type="text/javascript">
    // press the button
    var myButton = document.getElementById("idOfTheButtonToClick");
    myButton.click();
</script>

This assumes your button has an ID.

1) Here is a working auto-submit method: when page is loaded, the form will be immediately autosubmited (the values can be set with php variables too.)

<form action="page.php" name="FORM_NAME" method="post">
<input type="text" name="example1" value="YOUR_VALUE" />
<input type="submit" />
</form>
<SCRIPT TYPE="text/JavaScript">document.forms["FORM_NAME"].submit();</SCRIPT>

or use for any form on that page:

document.forms[0].submit();

2) you can use button-click (called after 1 second):

<SCRIPT TYPE="text/JavaScript">setInterval(function () {document.getElementById("myButtonId").click();}, 1000);</SCRIPT>
发布评论

评论列表(0)

  1. 暂无评论