Emo Scene Community

1000's of emo guys & girls!

Search soEmo

Top Emo Bands View All

8.3

Emo Lyrics View All

She cuts a vein although its much too dull, I say she's all alone, fighting for redemption, I know little pain little lust, I lose myself at night to feel the rush, of tearing my skin apart, now take this sadness and close your eyes love We Sleep Forever, by Aiden

Emo Forums » Help And Advice (Reply)

Emo Pictures - xXxChrisJWxXx
xXxChrisJWxXx
Posts: 1546
HTML Help Apr 06 2013, 04:47 PM
This may seem a strange one but I'm building a website and I'm stuck on the coding. Basically I have a password box (No button as I haven't got around to code one yet so just hitting the enter key), when this box meets a condition I want it to navigate to another page. The code I have so far is: <form> Please enter your shoot ID: <input type="password" name="pwd"> </form> <script type="text/JavaScript"> function checkValue() { var txtCtrl = document.getElementById("pwd"); var txtValue = txtCtrl.value; if (txtValue == "22cff6") { Response.Redirect("/22CFF62.html"); } } </script> What I am looking for is something like: If pwd = "22cff6" Go to page "/22cff6.html" Else If pwd = "25vhj3" Go to page "/25vhj3.html" Else ErrorMsg = "Sorry you have entered an incorrect password, please check your password and try again" End If Any ideas?? http://cjphotography.3owl.com/shoots.html

Replies

Emo Pictures - xXeMoRaCeRXx
xXeMoRaCeRXx
Posts: 18262
Apr 07 2013, 11:53 AM
Best done in PHP, but it could be done in JavaScript if you cannot use a PHP file. In PHP: <?php $password = (isset($_POST['password'])) ? trim(htmlentities($_POST['password'], ENT_QUOTES, 'UTF-8')) : ''; if (isset($_POST['submit']) && $_POST['submit'] == 'Submit') { if ($password == "password1") { header( 'Location: http://www.yoursite.com/page1.html' ); } else if ($password == "password2") { header( 'Location: http://www.yoursite.com/page2.html' ); } //etc.. } ?> <form action="formpage.php" method="post"> <input type="password" name="password" /> <input type="submit" name="submit" value="Submit" /> </form>
Emo Pictures - xXxChrisJWxXx
xXxChrisJWxXx
Posts: 1546
Apr 07 2013, 04:23 PM
I was completely confused by PHP so I used this: <script type="text/javascript"> function redirect() { var id=document.getElementById('id'); if(id.value=='22cff6') { location.href='22CFF62.html'; } else if(id.value=='aaaa') { location.href='index.html'; } else { alert("Sorry you have entered an incorrect password, please check your password and try again"); } } </script> <input type="password" id="id" value=""> <input type="button" value="GO" onclick="redirect();"> <noscript>

To use this page you will need a JavaScript enabled device.

</noscript>
Emo Pictures - xXeMoRaCeRXx
xXeMoRaCeRXx
Posts: 18262
Apr 08 2013, 02:10 PM
Ok cool that's fine. On site with loads of visitors though something to think about is not everyone has JavaScript enabled. It's going to be a very small percentage, but I'm fussy with this site :p e.g your account homepage on here uses some JavaScript but will still work fine without it via a different set of coding.
Emo Pictures - xXxChrisJWxXx
xXxChrisJWxXx
Posts: 1546
Apr 12 2013, 11:39 AM
I wasnt really sure what to do with the PHP and I don't think I'll have many visitors, yet anyway
Bones
Posts: 1726
Apr 13 2013, 01:27 PM
and I did level 3 ict and im like :O wawhat
Emo Pictures - xXeMoRaCeRXx
xXeMoRaCeRXx
Posts: 18262
Apr 14 2013, 07:11 AM
Concentrate on taking pics Bekah :D
Emo Pictures - xXxChrisJWxXx
xXxChrisJWxXx
Posts: 1546
Apr 16 2013, 11:03 AM
Right I added a text box in PHP which used the form go.PHP to redirect to other pages now the code below works: <?php If ($_POST = "NUSNC13"); $page = $_POST["page"]; header("Location: nusnc13.html") ; ?> But I can not get it to work with Elseif and I do not know what is wrong with my code, any ideas: <?php If ($_POST = "NUSNC13") $page = $_POST["page"]; header("Location: nusnc13.html") ; Elseif($_POST = "home") $page = $_POST["page"]; header("Location: index.html") ; ?> I also need an Else which will pop up "Warning check your password" kind of dialogue box if anything else is entered, any ideas?
Emo Pictures - xXeMoRaCeRXx
xXeMoRaCeRXx
Posts: 18262
Apr 16 2013, 02:22 PM
well one thing for sure it needs to be: if ($_POST == "NUSNC13") with the double equals
Bones
Posts: 1726
May 10 2013, 09:30 AM
yes yes agree with that hmmm yes!! lol
May 19 2013, 12:21 AM
You wouldn't use PHP to make the "wrong psswd" thing come up... What you would need to do is validate the input form via JS before the POST is sent to be validated by PHP on the server side. Unfortunately, this will require you to use something like AJAX to make an asynchronous request to your server to get the password, and validate it -- judging by the "complexity" of the scripts you've been presenting, I'd suggest reading up on this more before you start diddling with AJAX, XMLHTTPRequest objects etc...the security vulns you'd be exposing yourself to by passing your password DB to the client for JS to validate it could be horrible-bad shit if you fucked anything up. PERSONALLY: I would use "ghetto ajax" for this -- i.e. put the form on a page with a seamless iframe, and make its action="whateverIsInThatIframe" (which would be your PHP form handler) so that it appears to be behaving like an asynchronous request. It would look smoother to your users and be more secure.
Bones
Posts: 1726
May 19 2013, 05:24 AM
ghetto ajax :O ooow oooow :P xx
Emo Pictures - nikkiwest
nikkiwest
Posts: 2440
May 22 2013, 07:42 PM
I'm with Bekah on this... I am amazed by people that know how to do HTML formatting.
Emo Pictures - xXeMoRaCeRXx
xXeMoRaCeRXx
Posts: 18262
May 24 2013, 01:00 PM
Be amazed by me then :P
Bones
Posts: 1726
May 27 2013, 02:53 AM
shut up chocolate bar..i think you have achieved that much already!!! :P xx

Add Reply

  • Please note: Comments soEmo.co.uk considers to be totally unrelated spam will be removed.

Featured Users View More