Invoke a page click and commit

Asked

Viewed 44 times

2

I’m not gonna post code on the question because I don’t know the beginning. I have a page in HTML and with want to know if it is possible, with PHP invoke click action, etc, in selectors for example .classe#id.

Example:

<body>
    <button id='go'>Meu botão 1</button>
    <button id='ex'>Meu botão 2</button>
</body>

In an external PHP it is possible to request the click on button#go or button#ex? If yes, how?

  • Immediate response: no. Click is a DOM event, and PHP, because it is a preprocessor, does not interact with the DOM after creating the page, as does Javascript, for example. It is possible with PHP to write a Javascript function to manipulate the DOM.

  • You can even run some PHP code with Javascript (ajax).

2 answers

1

PHP does not do this, but it is possible to make PHP call who does - Javascript with Jquery.

PHP runs on the server, click happens on the client - in the browser.

What you can do is PHP generate a Javascript code that does the click event.

<script>
    <?php if ($habilita_clique_go) { ?>
        $('#go').click();
    <?php } ?>

    <?php if ($habilita_clique_ex) { ?>
        $('#ex').click();
    <?php } ?>
</script>

0


Researching and finding more terms for research, I found libraries that do this, as is the case with Goutte, in addition to the Simpletest has a similar tool, etc., is usually geared towards functional testing/system testing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.