简体   繁体   中英

Is it possible to automatically submit a php form

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?

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);
?> 

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.

IF you are php programmer then you might not want any javascript answer. the best solution to this is

1.USE A PROXY like paros or HTTP analyser they will give u the insight how site's form is structued

2.notE down the forms POST OR GET VALUE and their SYNTAX FROM THE HTTP analyzer or paros proxy.

read this tutorial it is the best tutorial out there

http://www.html-form-guide.com/php-form/php-form-submit.html

4.change the content of $_post or $_get according to their structure which you have noted down in

paros or HTTP analyser

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM