Jump to content

Recommended Posts

Hi,

 

I have a form field which takes any input and passes the input to a php script, what I need is a javascript prompt so if the form input is ABC it prompts for a pin number, and then both the inputs are passed to php page, however if the input is anything other than ABC it doesnt run a prompt...

 

Is there a way of doing this as a pop up prompt box rather than just passing to a php page that says if ($var =- "ABC"){ //INSERT POP UP PROMPT HERE } else { //JUST CARRY ON } etc....

Link to comment
https://forums.phpfreaks.com/topic/129480-js-prompt-for-input-to-work-with-php/
Share on other sites

This sounds like a javascript question.. i think.. i am not sure what your asking!!

 

me either

 

 

@wmguk

in your subject you have "JS prompt for input to work with PHP", so i believe this belongs in the javascript section.  But yes you can check with PHP and

 

if($var == "ABC") {
// your javascript pop up code
}
else {
// go to next page or w/e
}

 

We need to see your current code where you want to do this.

at the moment there is no code, I simply have a form with an input, that goes to a php script to verify if the code entered is authorised.

 

If I use php then I will have to have a secondary script, so that if code = ABC then prompt for a pin number... then if the pin and code is authorised then show the page, but what I wanted to do was show a javascript prompt popup for the pin if the code entered was ABC...

 

that way getting rid of the middle php code

 

I'm sure I havent described this well but its the only way I can describe it really

 

ENTER CODE -> IF ABC the prompt for PIN, Else -> VERIFY THE INFO AND SHOW THE PAGE

Okay the part i dont get is..

wouldn't you have the javascript prompt you for a security code when "code = ABC" remember i have no idea what code refers to or if ABC is unique to each user or what.. i really need more info..

from what i am reading you enter a code if thats equal to abc you ask for a PIN.. if ABC is static then why submit it.. why not have a JS to add the form element ? if its not static you could use AJAX to validate it

ah ok, its a photography site, most people dont require a "pin" code, so you just enter the album name... ie. if it is a wedding then you would just enter SmithJ for John Smiths wedding photo's....

 

however recently lots of school pics have been added and there is one album name, but the pin code ensures you only see your own childs photos, and obviously people who shouldnt look at school kiddies cant get access....

 

so basically ABC is the code for the school (all the parents get this info) - so if albumid = ABC then prompt for the pin code.... then the pin code is checked with the database to show the correct picture..

I guess you could do something like this:~

its just a draft (very quickly written)

<?php
$SomeData = "";
$RequirePIN = false;
if(!empty($_POST['SomeData']))
{
//Check if PIN is Req.
if($_POST['SomeData'] == "Private")
{
	$RequirePIN = true;
}

if(!$RequirePIN)
{
	header("LOCATION: display.php?SomeData=".$_POST['SomeData']);
}
if($RequirePIN && !empty($_POST['PIN']))
{
	$_SESSION['PIN'] = $_POST['PIN'];
	//display.php MUST also check the Database PIN with the $_SESSION['PIN']
	header("LOCATION: display.php?SomeData=".$_POST['SomeData']);
	exit;
}
$SomeData = $_POST['SomeData'];
}

?>

<form method="POST">
<input type="text" name="SomeData" value="<?php echo $SomeData ?>">
<?php
if($RequirePIN)
{
?>
<input type="text" name="PIN" value="123">
<?php
}
?>
<input type="submit" value="Submit">
</form>

ok, i see where you are going with that, and yes thats true, it would take out the need for an extra check within the script.php page, however I just like the look of a javascript prompt popup.... but I can certainly play with the code you have given me, drop the idea of JS and just go with pure php authorisation...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.