简体   繁体   English

是否可以自动提交php表单

[英]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). 我有一个网站,其中有几个php表单,我想用自动生成的内容填写这些表单(目的是为了行使用户可以提交的不同内容)。 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? 有没有办法使用webtoolkit,java脚本等执行此操作?

If you are already familiar with php, why not use php on the "client side" as well? 如果您已经熟悉php,为什么不也要在“客户端”上使用php? You can use the Client URL package to submit POST data to a web form. 您可以使用客户端URL包将POST数据提交到Web表单。 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. PHPUnit是用于单元测试 PHP应用程序的出色框架

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. 您还可以编写Selenium测试 ,该测试使用JavaScript与您的页面进行交互。

IF you are php programmer then you might not want any javascript answer. 如果您是php程序员,那么您可能不想要任何JavaScript答案。 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 1.使用像paros或HTTP分析器这样的代理,它们将使您了解如何构建网站的表单

2.notE down the forms POST OR GET VALUE and their SYNTAX FROM THE HTTP analyzer or paros proxy. 2.注意从HTTP分析器或paros代理中查找表格POST或GET VALUE及其语法。

read this tutorial it is the best tutorial out there 阅读本教程,这是那里最好的教程

http://www.html-form-guide.com/php-form/php-form-submit.html 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 4.根据您在其中记下的结构更改$ _post或$ _get的内容

paros or HTTP analyser paros或HTTP分析器

if you name your form using the id attribute, you can call the javascript function 如果您使用id属性命名表单,则可以调用javascript函数

document. 文献。 myform .submit(); myform .submit();

where myform is the name of that form. myform是该表单的名称。

You could have an onload event attached to the body element which would submit the forms automatically. 您可以在body元素上附加一个onload事件,该事件将自动提交表单。

<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. 当然,使用jQuery或其他API可以更好地完成此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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