I need POP up window after IF and ELSE statement - php

I need pop up window after IF and Else statement heres my code.
else if ($selected_radio=='q1yes' && $status=='yes' && $bus=='retail' && $retail=='retailyes' && $phonetype=='dsl' && $checks=='checkyes' ) {
$q1yes_status = 'checked';
$yes_status = 'checked';
$service_status='checked';
$autorepair_status='checked';
$analog_status='checked';
$checkyes_status='checked';
echo "your answer is yes yes retail autorepair dsl yes"; <<<< --- that text should change pop up window URL like "http://formsignup.php" instead of text message. I'm not sure if that possible to do Pop up inside ECHO.
I appreciated your help!

Would the POP up window be done is JavaScript?
So where you wanted a POP up window you could echo/print the required JavaScript?
Using code like...
window.open("http://formsignup.php","Window Name",width=430,height=360");
This code could be included in the HEAD of the document, and then called in the main BODY.
Or this could all be put in the BODY like...
<script language="JavaScript">
window.open("http://formsignup.php","Window Name",width=430,height=360");
</script>

echo some javascript code, then when the page sis sent to the browser the browser will fire the javascript code causing your popup to show:
echo "<script>alert('your answer is yes yes retail autorepair dsl yes');</script>";
for example:

You can echo some javascript that loads a new window?
echo "<script>window.open('url to open','window name');</script>";

Related

Execute jquery in if statement

I got a login system, and what I want to do is to hide a div and show another div when the user types the incorrect login details. However it doesn't seem to work.
if(...) { // here I check if the user enters the correct information
... //much code inside
} else { // if incorrect info, do this
echo "<script>$('#jqueryhide2').hide();
$('#jqueryhide').show();</script>";
}
Tried to google a bit but can't find anything that could solve my problem.
put this code and also include your Jquery file -(dont forget)
echo "<script>
$('document').ready(function(){
$('#jqueryhide2').hide();
$('#jqueryhide').show();
});</script>";
I think you should missing the Onclick function like this:
<script>
$('loginId').Onclick(function(){
$('#jqueryhide2').hide();
$('#jqueryhide').show();
});</script>";
You don't need the script tags inside your statement. You can simply do the following. ( Make sure jqueryhide and jqueryhide2 are a part of the DOM. )
if (blah == blah )
{
$('#jqueryhide2').show();
$('#jqueryhide').hide();
}
else
{
$('#jqueryhide2').hide();
$('#jqueryhide').show();
}

View full site with cookies, javascript and mobile redirect

I have a website(www.website.com) and a mobile site (m.website.com) and I'm trying to allow users to "View Full Site" if they want from mobile. Currently I am using some Javascript to check screen width on full site then redirecting to mobile.
if (screen.width <= 699) {
document.location = "http://m.website.com";
}
This works fine. On the mobile site there is a "View Full Site" button. When you click this it redirects you to my script "force_desktop.php" which sets a cookie and then sends you to the main site.
<?php
setcookie("force_desktop", "1");
header("Location: http://www.mywebsite.com");
?>
Now that we set a cookie and redirected to the main website we need to check for the cookie instead of just checking for the screen width.
Logic
If Cookie force_desktop is found
Then exit
Else
run screen size test
Here is the code I attempted to use but doesn't work. This code is placed in my head.php file which will be run on every page and is placed between the script opening and closing tags.
Attempt 1
if($_COOKIE['force_desktop'] == '1' {
exit;
} else if($_COOKIE['force_desktop'] != '1' {
if (screen.width <= 699) {
document.location = "http://m.website.com";
}
};
Attempt 2
if(isset ($_COOKIE["force_desktop"])){
exit;
else
if (screen.width <= 699) {
document.location = "http://m.mywebsite.com";
};
Alternative logic that could work
IF Cookie force_desktop is not found AND screen.width <= 699
Then redirect to m.myseite.com
Else
Exit
Note
I have run the following script to make sure a cookie is being placed, and it is.
<?php
print_r($_COOKIE);
?>
I've run out of ideas and know my coding isn't correct, especially the If/Else statement within the If/Else statement. I also am not sure if it is better to use the "isset" to see if the cookie is being used or ($_COOKIES['variable'] == "#"). I'd really appreciate some good feedback on this one.
Thanks in advance for your help and suggestions,
Matt
You're mixing JavaScript and PHP. You're trying to use screen.width in your PHP script, which doesn't make sense. You need to use an echo statement to output the JavaScript into the page. It'll then check the user's screen resolution and do the redirect.
Try this:
if(isset ($_COOKIE["force_desktop"])){
exit;
}
else
{
echo '<script>
if (screen.width <= 699) {
document.location = "http://m.mywebsite.com";}
</script>';
};
you should do this test at the top of the php page, and for sure you cannot mix php and java script like this
u can alter this code like
<?php
$flag = 0;
if(isset($_COOKIE['force_desktop']))$flag++;
?>
later in the page use the code as soon as <head> tag starts
..
..
<head>
<?php
if(!$flag){
echo '<script>
if (screen.width <= 699) {
document.location = "http://m.mywebsite.com";
</script>';
}
?>
You cannot mix javascript and PHP, javascript is front end and PHP is back end. Try something like this:
if( $something ){
Header("Location: somewhere.php");
}

Prompt not working with IF statement

Again, I'm very new to programming with PHP and JS. I pulled off a piece of code that is a JS prompt function within PHP to confirm a modification to data. The $confirmdelete variable is indeed "YES" when I type that in the prompt... (I checked it with an echo), but it keeps producing the "MODIFICATION ABORTED" message no matter what (and of course not changing the data).
Is my IF statement bad? Hope it is just a newb typo... Is this even a good way to do this? Thanks for any help...
<?php
//prompt function
function prompt($prompt_msg){
echo("<script type='text/javascript'> var answer = prompt('".$prompt_msg."'); </script>");
$answer = "<script type='text/javascript'> document.write(answer); </script>";
return($answer);
}
$prompt_msg = "Are you SURE you wish to make a modification? Type YES to confirm: ";
$confirmdelete = prompt($prompt_msg);
if ($confirmdelete != "YES") {
echo "MODIFICATION ABORTED <br><br>
<a href='index.php'>RETURN TO MAIN PAGE</a>";
exit();
}
?>
Ummmmm....
You cannot do that.
When the PHP code is outputted -- it is done. There is no more talking back to the server unless you add some AJAX handlers.
The only think your code outputs is this:
<script type='text/javascript'> var answer = prompt('Are you SURE you wish to make a modification? Type YES to confirm: '); </script>MODIFICATION ABORTED <br><br>
<a href='index.php'>RETURN TO MAIN PAGE</a>
Demo

Issue with Calling JS function through PHP based on IF statement

I have a web based tool. There is a login where username, loggedin and authorised are stored in session variables.
There is one particular page where I have a form that has multiple buttons, I wish to disable one button based on what the users authorisation level is. So if authorised is 0 (user) the button is disabled, else it's enabled as I've only got two authorisation levels, 0 & 1.
I've attached what I've done below, and to me it looks right, obviously it's not!
Here is the JQuery function:
$(function disable(){
$('#signBtn').attr('disabled', true);
});
Here is the PHP code:
if($_SESSION['authorised'] == '0')
{
echo "<SCRIPT LANGUAGE='javascript'>disable();</SCRIPT>";
}
Here is my HTML code:
<input type=\"submit\" name=\"save\" id = \"signBtn\" class = 'eBtnSubmit' value=\"Sign off by Chairperson\" />
If there is anyone out there that can see what my problem is I would really appreciate it...this is my last piece of the puzzle and I'm presenting this today (Software Intern).
So basically if the level is 0 call the function.
Regards,
Gary
No warranty because I don't have all the code
Change the static JavaScript Code to this
var disableSingoff = function () {
$('#signBtn').attr('disabled', true);
}
In your original code, you execute the disable() function right when the DOM is ready by wrapping it in $().
Change the PHP code to this
if($_SESSION['authorised'] == '0') {
echo "<script>$(function () { disableSignoff(); })</script>";
}
It might be easier to simply set the value in the HTML if possible
if($_SESSION['authorised'] == '0'){
echo '<button type="button" disabled="disabled">Click Me!</button>';
}else{
echo '<button type="button">Click Me!</button>';
}
This would work before the page even starts loading.
The other option would be to hook the window on load function.
window.onload = (function(){ [...] }
is the <input type=\"submit\" name=\"save\" id = \"signBtn\" class = 'eBtnSubmit' value=\"Sign off by Chairperson\" /> being echoed from a php statement? if not you can get rid of all the '\'s. they are not necessary when writing strictly html.

improve my PHP user interaction

I have a situation where a user fills out 1 of 2 forms on a registration page and is sent to a software download page. If they sign up as a new user, form is processed inserted into a MySQL database and they go to the page no problem.
Here is my issue. If they are a returning user and enter a license key, the processor script checks to see if its valid against the database and if it is it sends them to the software download page. If it is NOT a valid license key (heres what I dont like) the screen goes to the url of the script, page is white, an alert pops down telling them its not a valid license key and they are returned to the registration page to try again. I hate this. I need to figure out a way to either pop the alert on the registration page w/o leaving it or better yet display some kind of message on the page. One drawback is that the script is and always will be on a different server than my forms. Ive tried curl and had success with other situations but can't close the MySQL connection on this one. Is there another way to achieve some semblance of "cross domain AJAX" I would really like it to not go to the script url/white page/alert then return them. I would like it to happen all on one page. Here is that part of my script:
if ($_POST['license_code'] != "")
{
$result = mysql_query("(//mysql stuff here)");
if (($row = mysql_fetch_assoc($result)))
{
header("Location: http://" . $redirect);
}
//here is the part I dont like
else
{
echo "<html>\n";
echo "<body>\n";
echo "<script language=\"Javascript\">\n";
echo "alert (\"The license ID you entered was not correct.\");\n";
echo "window.location=\"http://www.registrationpageURL.php\";\n";
echo "</script>\n";
echo "</html>\n";
echo "</body>\n";
}
mysql_close($link);
}
//I use jquery valiadate.js for CS validation, but realize this is necessary and would like it to behave like the desired result for the above
else
{
if (strpos($_POST['email1'], '#') === false)
{
echo "<html>\n";
echo "<body>\n";
echo "<script language=\"Javascript\">\n";
echo "alert (\"The email address you entered was not correct.\");\n";
echo "window.location=\"http://www.registrationpageURL.php\";\n";
echo "</script>\n";
echo "</html>\n";
echo "</body>\n";
return;
}
thx
Is it possible to remove the alert and when you redirect to registrationpage.php also send a parameter using the redirect url and popup an alert or error message after the redirect ?
Look into using AJAX. jQuery has a great API for this:
http://api.jquery.com/jQuery.get/
http://api.jquery.com/load/
EDITIED - For cross-domain
You could do something like this:
<div id="results"></div>
<script type="text/javascript">
$("#the_form").submit(function() {
$.getJSON("http://remote.domain/script/to/validate.php?data=" + escape($(this).serialize()) + "&callback=?", function(data) {
$("#results").html(data);
});
return false;
});
</script>
This will (once the IDs are pointed at the correct elements) intercept the form submission, pull together the values from the form (through the serialize() function), and shoot it out to the validation script via AJAX. The output of the script is displayed in the #results div.
Hope this helps!

Categories