I've seen some similar questions, but they are not totally the same. If I missed in my search, please forgive me. However this what I have so far:
I've created a form that has an input field for the access code and a submit button, as follows:
<form action="#" method="POST" name="access">
<p style="text-align: center;">
<input id="access_code" type="Text" name="access_code" value="" />
<input type="Submit" name="access1" value="Register" />
</p>
</form>
Then on the backend, I started with something like this:
if(isset($_POST['Register'])){
if(empty($_POST['access_code'])){
echo "Access Code Must Be Entered";
}
}
$DisplayForm = True;
if(isset($_POST['Register'])){
$DisplayForm = False;
echo $_POST['access_code'];
}
if ($DisplayForm){
?>
<form action="#" method="POST" name="access">
<input type="Text" name="access_code" value=" " />
<input type="Submit" name="access1" value="Register" />
</form>
<?php
}
echo "<a href="http://www.mysite.com/<?php echo $_POST['access_code'];?>"<img src="http://www.mysite.com/images/logo.jpg"></a>"
I realize my final echo syntax is broken, but not quite sure how to write out.
All I want to do is have this form redirect a user to a custom page that's based on the access code they have been given and call it with a short code. For example, if the access code is "help", they are sent to a page of http://www.mysite.com/help, or if the password is "contact", they are then sent to a page of http://www.mysite.com/contact.
I initially wanted to base this on the password protection feature in WordPress, where if the page password was also "help" it would just redirect to that URL, but I may be over complicating things.
So the new code should look like this:
if(isset($_POST['Register'])){
if(empty($_POST['access_code'])){
echo "Access Code Must Be Entered";
}
}
$DisplayForm = True;
if(isset($_POST['Register'])){
$DisplayForm = False;
echo $_POST['access_code'];
}
if ($DisplayForm){
?>
<form action="/" method="$_GET" name="access">
<input type="Text" name="name" value="" />
<input type="Submit" name="access1" value="Register" />
</form>
<?Php
}
wp_redirect(get_bloginfo('url').'/'.$_POST['access_code']);
I think I understand it all except the execution of the before get_header()
part. How would I do that?
$_POST
variable to make sure its valid, and then usingwp_redirect()
to go to the permalink of the page in question. Sounds like a fun project, honestly!