0

I have a hyperlink <a href="<?php echo http://www.google.com?q=".$dynamicsearch; ?>" title="Link"></a> that is on a cakephp view.

When I click the link the $dynamicsearch needs to be updated every time the link is clicked.

I tried to create a function in the cakephp controller by calling the action generate_random_word on the controller. When I click the link the controller would choose a random word on demand and then add it as the parameter and then redirect the url to open google in the browser with the random word.

I have tried many ways but have not found the solution. Any ideas!

1 Answer 1

1

I think you have a misconception of how PHP works in general. PHP generates the HTML, then it's done. It will not continue running methods after the page has been loaded completely.

What you'll need is some form of javascript if you want to edit the link on click, and ajax if you need to generate the word from the server.

The specifics of the code is beyond the scope of an answer on StackOverflow, but hopefully this will point you in the right direction.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.