开发者

Accessing information outside an HTML form

At the beginning of my PHP page I have a form with a save (submit) button. Below I draw a list of items which are from the db. I now want the user to be able to tick the items he wants to select. My problem: All the information is outside my form. How can I access th开发者_StackOverflow中文版e generated information?

<form method="post" action="">
<input type="submit" name="save" class="inputButton" value="Save" />
</form>

PHP function below:

drawArticles($id, $option, $credit);

Contents of PHP function drawArticles():

..CONTENTS REDUCED..
echo        "<div class='groupsTickbox' name='".$aid."'><input type='checkbox'></div>";
echo        "<div class=\"divListGroups\">";
..CONTENTS REDUCED..


You MUST insert all form elements in <form> tag if you want them to be automatically included in POST request. Otherwise, you'll need to manually code JavaScript onSubmit() handler to include values of those DOM nodes to the form request. You can surround whole page with <form> elements, if that matters.


You can either use Javascript's native DOM traversal mathods such as document.getElementById( ) and document.getElementsByTagName( ) to find the DOM elements you need, or you can use jQuery as follows: var tickbox = $('div.groupsTickbox');

If you do it this way, you will have to assign an onsubmit handler to the form and generate your own submission data. If you don't want to do this, then you have to put your elements inside the <form> tag.

If you're not already, you should look into jQuery purely for it's power in traversing the DOM (it has many other benefits as well)


You can always save key information about their query in a session var and save it with the post, since the information is being displayed on the page. If it is a second form there are some very interesting tutorials on how to deal with multi page forms on the web:

  • http://www.html-form-guide.com/php-form/php-order-form.html
  • http://docstore.mik.ua/orelly/webprog/pcook/ch09_04.htm
  • http://www.phpriot.com/articles/multi-step-wizards/2


Have a look at this; it shows you can access DOM information (arbitrary nodes in the document) using javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜