ryanmetzler3 Posted December 16, 2013 Share Posted December 16, 2013 I have a comment system that runs on ajax. There is an html form that has a field for name, email, and comment. Then there is a submit button. I also have a button that gives you the option to log in. Here is the code for that: <div id="addCommentContainer"> <div id="login"><input type="submit" id="submit" value="Or Login" onclick="window.location='/LoginScripts/login.php'" /></div> <p>Add a Comment</p> <form id="addCommentForm" method="post" action=""> <label for="name">Your Name</label> <input type="text" name="name" id="name" /> <label for="email">Your Email</label> <input type="text" name="email" id="email" /> <label for="body">Comment Body</label> <textarea name="body" id="body" cols="20" rows="5"></textarea> <input type="submit" id="submit" value="Submit" /> </form> </div> If a user chooses to log in, then they would no longer need to type their name and email in each time they want to comment. So I was going to put a PHP if-statement around the name, email, and login button. This way they will not display if the user is logged in. I would then use another if-statement to redefine their name and email that is sent to the ajax. Something like this: <div id="addCommentContainer"> <?php if(!$username && !$userid) : ?> <div id="login"><input type="submit" id="submit" value="Or Login" onclick="window.location='/LoginScripts/login.php'" /></div> <p>Add a Comment</p> <form id="addCommentForm" method="post" action=""> <label for="name">Your Name</label> <input type="text" name="name" id="name" /> <label for="email">Your Email</label> <input type="text" name="email" id="email" /> <?php endif; ?> <?php if($username && $userid) : ?> // redefine name and email that is sent to ajax. Some kind of mysql_query that will grab it from the DB of users. <?php endif; ?> <label for="body">Comment Body</label> <textarea name="body" id="body" cols="20" rows="5"></textarea> <input type="submit" id="submit" value="Submit" /> </form> </div> I am very confused on how to pull this off. The code requires that name, email, and comment are filled before you can press the submit button. So I somehow need to redefine those values using a mysql_query for logged in users before they press the submit button. If anyone has any input on how to do this, that would be amazing! Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted December 16, 2013 Solution Share Posted December 16, 2013 Surely, all you need will be the userid to identify the user. Put the userid in a hidden field in the form with comments and pass that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.