tags:

views:

109

answers:

4

I have a website in which I have a several php forms that I would like to fill out with auto generated content (for the purposes of exercising different content the user could submit). I would like to write a client side application that enables me to do so.

Is there any way either using webtoolkit, java script etc of doing this?

Thank all for your help, PHPNoob

A: 

if you name your form using the id attribute, you can call the javascript function

document.myform.submit();

where myform is the name of that form.

Foxtrot
+3  A: 

If you are already familiar with php, why not use php on the "client side" as well? You can use the Client URL package to submit POST data to a web form. Example:

<?php
$ch = curl_init();
$data = array('name' => 'phpnoob', 'address' => 'somewhere');

curl_setopt($ch, CURLOPT_URL, 'http://localhost/url/to/your/php/form.php'); // use the URL that shows up in your <form action="...url..."> tag
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?> 
Heinzi
I don't mind the downvote, but I'd be grateful for an explanation so that I can improve my answer...
Heinzi
@Heinzi: I believe it's on ethical grounds because they think phpnoob is going to use this information to spam. I strongly disagree since there is no indication of that and at stack overflow provide answers to questions, period, without going too much into unrelated ethic discussions. However downvotes are completely subjective so there is nothing you can do about it.
Andreas Bonini
+1  A: 

It would probably be better, more stable and more efficient to mock a submission by sending data directly into your application. PHPUnit is a great framework for unit testing PHP applications.

But yes, it would be possible to write a client side submission too. You could also write Selenium tests, which use JavaScript to interact with your page.

PatrikAkerstrand
A: 

Hey phpnoob,

You could have an onload event attached to the body element which would submit the forms automatically.

<body onload="document.form1.submit();document.form2.submit();">
    <form id="form1" action="url" method="post">

    </form>

    <form id="form2" action="url" method="post">

    </form>
</body>

Of course this would be completed better using jQuery or another API.

Metropolis