Jump to content

sticky form help


mattrd

Recommended Posts

I want to make my email input and password input sticky so if they fill out email but don't fill out password they don't both reset. I would assume that I should put the input value as

value=\"if (isset($_POST['email'])) echo $_POST['email'];\"

but this isn't working and I am getting an error what am I doing wrong? If anyone could help me I'd really appreciate it. thank you!

 

here is all my code (without the values in the inputs)

 

<div id="right_nav">
<div id="tip">Welcome to the Berks County Foster Parent Association Website</div>
<div id="login">
	<?php
		/* write a conditional to see if form was submitted */
		if (isset($_POST['submitted'])) {
			if (!empty($_POST['email']) && !empty($_POST['password'])) {
				echo "<p class=\"center bold\">Welcome User!<br />\n
				You are currently logged in.</p><p class=\"center\">\n\n
				<a href=\"#\" style=\"left:0\">Logout</a></p></div>";
				include("user_nav.php");
			} else {
				echo "<ul>";
				if (!empty($_POST['email'])) {
					$email = $_POST['email'];
				} else {
					$email = NULL;
					echo "<li>You didn't enter an email address!</li>";
				}
				if (!empty($_POST['password'])) {
					$password = $_POST['password'];
				} else {
					$password = NULL;
					echo "<li>You didn't enter a password!</li>";
				}
				echo "</ul>";
				echo "<form action=\"index.php\" method=\"post\">
						<p><span>Email Address:</span><br /><input class=\"login_input\" type=\"text\" name=\"email\" /></p>
						<p><span>Password:</span><br /><input class=\"login_input\" type=\"password\" name=\"password\" /></p>
						<p><input id=\"login_button\" type=\"submit\" name=\"submit\" value=\"Login\" /><a href=\"#\">forgot password</a></p>
						<input type=\"hidden\" name=\"submitted\" value=\"TRUE\" />
					</form></div>";
					include("general_nav.php");
			}
		} else {
			echo "<form action=\"index.php\" method=\"post\">
						<p><span>Email Address:</span><br /><input class=\"login_input\" type=\"text\" name=\"email\" /></p>
						<p><span>Password:</span><br /><input class=\"login_input\" type=\"password\" name=\"password\" /></p>
						<p><input id=\"login_button\" type=\"submit\" name=\"submit\" value=\"Login\" /><a href=\"#\">forgot password</a></p>
						<input type=\"hidden\" name=\"submitted\" value=\"TRUE\" />
					</form></div>";
					include("general_nav.php");
		}
	?>
</div>

 

 

Link to comment
https://forums.phpfreaks.com/topic/144648-sticky-form-help/
Share on other sites

I would add something like this just befor your echo:

if (!empty($_POST['email'])){$email = $_POST['email'];}
if (!empty($_POST['password'])){$password = $_POST['password'];}

 

So your code would look like this:

<div id="right_nav">
<div id="tip">Welcome to the Berks County Foster Parent Association Website</div>
<div id="login">
	<?php
		/* write a conditional to see if form was submitted */
		if (isset($_POST['submitted'])) {
			if (!empty($_POST['email']) && !empty($_POST['password'])) {
				echo "<p class=\"center bold\">Welcome User!<br />\n
				You are currently logged in.</p><p class=\"center\">\n\n
				<a href=\"#\" style=\"left:0\">Logout</a></p></div>";
				include("user_nav.php");
			} else {
				echo "<ul>";
				if (!empty($_POST['email'])) {
					$email = $_POST['email'];
				} else {
					$email = NULL;
					echo "<li>You didn't enter an email address!</li>";
				}
				if (!empty($_POST['password'])) {
					$password = $_POST['password'];
				} else {
					$password = NULL;
					echo "<li>You didn't enter a password!</li>";
				}
				echo "</ul>";
				if (!empty($_POST['email'])){$email = $_POST['email'];}
				if (!empty($_POST['password'])){$password = $_POST['password'];}
				echo "<form action=\"test.php\" method=\"post\">
				<p><span>Email Address:</span><br /><input class=\"login_input\" type=\"text\" name=\"email\" value=\"$email\" /></p>
				<p><span>Password:</span><br /><input class=\"login_input\" type=\"password\" name=\"password\" value=\"$password\" /></p>
				<p><input id=\"login_button\" type=\"submit\" name=\"submit\" value=\"Login\" /><a href=\"#\">forgot password</a></p>
				<input type=\"hidden\" name=\"submitted\" value=\"TRUE\" />
				</form></div>";
					include("general_nav.php");
			}
		} else {
			echo "<form action=\"index.php\" method=\"post\">
						<p><span>Email Address:</span><br /><input class=\"login_input\" type=\"text\" name=\"email\" /></p>
						<p><span>Password:</span><br /><input class=\"login_input\" type=\"password\" name=\"password\" /></p>
						<p><input id=\"login_button\" type=\"submit\" name=\"submit\" value=\"Login\" /><a href=\"#\">forgot password</a></p>
						<input type=\"hidden\" name=\"submitted\" value=\"TRUE\" />
					</form></div>";
					include("general_nav.php");
		}
	?>
</div>

Link to comment
https://forums.phpfreaks.com/topic/144648-sticky-form-help/#findComment-759046
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.