1
votes

This may not be possible, which is why I can't find the answer, but is it possible to pass variables from HTML to PHP without a form?

I'm trying to create a template that will use HTML I import into a Wordpress Page. I want to be able to put certain divs in different parts of the template. Think of a table, where I put the divs in different cells.

Any help you can give me would be greatly appreciated. Thank you!

edit: I haven't created the template code yet, since I'm not sure how to without the answer to my question. But here's an example of the code I'm pulling from:

<div id="text-column">

<div class="scarlet_underline"> <p class="toc_dept"><a href="XXX"><img src="XXX" width="112" height="36" alt="Forum" border="0"/></a></p> <p class="toc_item"><a href="XXX">University futures; Science’s influence; Can geoengineering be green?; Mineral reserves; Transforming conservation; Intelligent transportation; Personal health records.</a></p> </div>

<div class="scarlet_underline"> <p class="toc_dept"><a href="XXX"><img src="XXX" width="112" height="36" alt="From the Hill" border="0"/></a></p> <p class="toc_item"><a href="XXX">House approves bill to reform offshore oil drilling; Senate committee approves competitiveness bill; GAO investigates genetic test companies; House, Senate committees lay out plans for NASA’s future; Federal science and technology in brief.</a></p> </div>

So ideally, these two "scarlet_underline" divs would each be pulled separately, maybe by using the alt attribute? The template code would be something like:

<div class="forum"><?php code that pulls that div ?></div>

<other code other code>

<div class="hill"><?php code that pulls that div ?></div>

1
Can you show a bit of what your code is?Jonathan M
This is ambiguous. Please explain the process.Popnoodles

1 Answers

2
votes

Is it possible to pass variables from HTML to PHP without a form?

Yes, that is possible. PHP automatically creates variables for Cookies and parameters in the Query part of the request URI. Both can be send from the browser without any HTML form.

http://example.com/path/to/index.php?type=animal&name=narwhal#nose
\__/   \_________/ \_______________/ \_____________________/ \___/
 |          |             |                    |               |
scheme   authority       path                query          fragment
                                             ^^^^^

This request URI will make PHP create two entries in the $_GET superglobal:

$_GET['type'];    # animal
$_GET['name'];    # narwhal

See as well Variables From External SourcesDocs.