Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate multiple form submissions

Status
Not open for further replies.

jaredgalen

Programmer
May 28, 2003
34
LT
I have a php page that has a form that a user can submit.

This form gets submitted as soon as an item is selected from a drop down menu.
I need to automate a way that will select each option and get the resulting page.

There are no urls to use or anything, I can only get the pages through the drop down menu.

Any idea how to select each one so I can use the resulting data.

I would like to use java but any suggestions would be great.
Appreciate any help as I'm stumped...

jG
 
So what you need is a multiple select box, a list of options, and when you select an option, all of the options become selected and the form submits? How would you keep track of the data that was selected?

If you are creating the page dynamically, and need to pass certain selected values on, consider using <input type="hidden"> elements, for storage only.

P.S. By Java, did you mean Javascript? They are very different.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Hey chessbot,
thanks for replying. Okay I'll try and clarify.
The page I'm talking about has already been created and I can't change it.
It contains one drop down menu with about 500 options.
When one of these options is selected the form is submitted automatically, using javascript.
I want to be able to create a process where I can use a seperate application, be it web based or standalone, that can automate the process of selecting each of the options in the menu which will give me back the next page.

I want to parse the data from these resulting pages.
I am really not familiar enough with the concepts involved but I was wondering if it is possible to manually create a request object (i think thats the one) that I can submit which will contain the information that will make the php processing the request think it came from the submission of the form
 
Tell me if I'm wrong.
You need a page that
1. Opens an instance of the page.
2. For each option in the select, the page selets that option and submits the form.

Am I right?
What are you trying to accomplish in total? Do you need the information stored in the options and can't get it any other way? Can you be more general?

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
That's it, I need the information stored in the pages corresponding to each of the options.
The only way to get them is to select each one from the menu.
I need to parse all the data from these pages and put it into a database.
Perhaps I'm in the wrong forum for this, but could it be done with jsp's?

 
I don't know JSP, but here is a Javascript method. This method sends a form name through the POST method named "selpairs". It contains the values separated by the value of the sel variable. Make sure to set all of your pages.

Code:
<html>
<head>
<title>Form</title>
<script type="text/javascript">
// URL of select page
var select_page = "selects.html";

// Name of form on that page
var form_name = "selectform";

// Name of select on that page
var sel_name = "sel";

// Separator -- select an unused character.
var sep = "~";

function loadForm()
{
  var fulltext = "";
  var win = window.open(select_page,"myWin","width=0,height=0");
  if (!win) alert("Error: Failed to open page.");

  var ops = win.document.forms[form_name].elements[sel_name].options;
  for (var i=0;i<options.length;i++)
  {
    fulltext += ops[i].value;
    if (i<ops.length-1) fulltext += sep;
  }

  document.forms['myform'].elements['selpairs'].value = fulltext;
  document.forms['myform'].submit();
}
</script>
</head>
<body>
<form name="myform" action="target.php" method="post">
</form>
<textarea name="selpairs"></textarea><br><br>
<input type="button" value="Populate and submit!" onClick="loadForm();">
</body>
</html>

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Sorry -- that code doesn't work. Try this (I tested it this time):

Code:
<html>
<head>
<title>Form</title>
<script type="text/javascript">
/* Make sure to change the three values and the form target! */

/* URL of select page */
var select_page = "selects.html";

/* Name of form on that page */
var form_name = "my_form";

/* Name of select on that page */
var sel_name = "select_1";

/* Separator -- select an unused character. Use it for splitting (or exploding, or imploding...) */
var sep = "~";

function loadForm()
{
  var fulltext = "";
  var win = window.open(select_page,"myWin","width=10,height=10");
  if (!win) alert("Error: Failed to open page.");

  var ops = win.document.forms[form_name].elements[sel_name].options;
  for (var i=0;i<ops.length;i++)
  {
    fulltext += ops[i].value;
    if (i<ops.length-1) fulltext += sep;
  }

  window.document.forms['myform'].elements['selpairs'].value = fulltext;
  window.document.forms['myform'].submit();
  win.close();
}
</script>
</head>
<body>

<!-- Remember to change the target. -->

<form name="myform" action="target.php" method="post">
<textarea name="selpairs"></textarea>
</form><br>
<input type="button" value="Populate and submit!" onClick="loadForm();">
</body>
</html>

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Thanks a million Chessbot.
I'll try this out today.
What I need to do is try and capture each page and process it as it's returned.

Let's see if I can at least do that.

Thanks again

jG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top