Reputation: 211
I'd like to grab a value from my URL to pass it through to a hidden fields in Wordpress Contact Form 7.
For example, www.domain.com/?refid=1
Does anyone have any ideas on the best way this could be achieved?
I've got something alone the lines of the following to set the cookie:
< ?php if (isset($_GET['refid'])) { setcookie('COOKIE_refid', $_GET['refid'], (86400*30)); } ?>
Would this cookie store what I'm after?
Many thanks.
Upvotes: 0
Views: 593
Reputation: 3486
Would this cookie store what I'm after?
Have you tried it? It looks like it would create a 30 day cookie like such:
COOKIE_refId=1
If you want a hidden field, though, then this is not the solution. While the user will not see the cookie (unless they have some sort of packet sniffer or cookie inspector installed), this is not actually a hidden field. To send through a hidden field, you could try something like this when you write out the page with the contact form:
<!DOCUMENT HTML>
<html>
<head>
<title>Hidden Field Example</title>
</head>
<body>
<form method="POST" action="contact.php" id="contactform">
<!-- ... Your contact form fields here... -->
<?php
// Check if we need to output a refid hidden form field
if(isset($_GET['refid']) && !empty($_GET['refid'])){
// Use echo to send the hidden refid form field to the output stream/buffer
echo "<input type='hidden' id='hiddenRefId' name='refid' value='$_GET['refid']'>";
} /* else, there is no refid to include as a hidden field */
?>
</form>
</body>
</html>
I do not know the exact semantics of Contact Form 7 for Wordpress, but that should give you a general idea.
Upvotes: 1