URL variable not being set in PHP when using jquery mobile - php

i have a few pages and when the input is submitted it will go to a php file which checks the url variable this could be executeeffects.php?option=blockuser
but when i go to the page the page just says "undefined" in the executeeffects php file it has a checking feature to check if a variable is set, it echos out one thing if it is or another thing if it isnt, however i didnt make it echo undefined so i dont no where that is coming from, the code is below
can someone tell me if this is a problem with jquery mobile or if im missing something please?
block.php
<!DOCTYPE html>
<html>
<head>
<title>Ryan Kelly</title>
<meta name="viewport" content="width=device-width, initial-scale=1 user-scalable=no">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script src="effects.js"></script>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>Ryan Kelly</h1>
</div><!-- /header -->
<div data-role="content">
<label for="basic">Username:</label>
<input type="text" name="name" id="basic" value="" />
<input type="text" name="name" id="blocked" value="" />
Submit
<?php include('listusers.php'); ?>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
executeeffects.php
<?php
if(isset($_GET['option'])){
echo 'something is set!';
} else {
echo 'nothing is set!';
}
?>

You Said "i have a few pages and when the input is submitted it will go to a php file which checks the url variable this could be executeeffects.php?option=blockuser"
This:
<input type="text" name="name" id="basic" value="" />
<input type="text" name="name" id="blocked" value="" />
Submit
will not submit the value of the inputs unless you are using some type of jQuery that you have not posted in which case this will need to be done differently.
to submit the value of the inputs you need to use a <form>

Related

Jquery mobile page not opening php file [duplicate]

This question already has answers here:
jquery mobile w/ php login form
(2 answers)
Closed 5 years ago.
am trying to submit a form from a jquery-mobile page to a php file for processing but whenever i press the submit button it displays an "Error Loading Page" dialog.
I have tried looking at the w3schools website form submission example and am pretty sure my code is the same.This is my code.
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Jquery Mobile</title>
<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<!-- Include the jQuery library -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<!-- Include the jQuery Mobile library -->
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<style>
.ui-content {
margin-top:150px;
margin-left:500px;
margin-right:500px;
}
/* For mobile screens */
#media screen and (max-width: 480px) {
.ui-content{
margin:0px;
}
</style>
</head>
<body>
<div data-role="page" id="chat">
<div data-role="header"><h1>Welcome to the Streamline Chat App</h1></div>
<div data-role="main" class="ui-content">
<h3>Select a username to continue</h3>
<form method="post" action="login.php">
<label for="username" >Username:</label>
<input type="text" id="username" name="username">
<input type="submit" data-inline="true" value="Submit">
</form>
</div>
</div>
</body>
</html>
login.php
<?php
$username = $_POST['username'];
echo $username;
?>
Am wondering if am doing something wrong. Please help me out. Both files are in the same directory
I got the answer from another post here
Just needed to add data-ajax="false" to the form tag
<form method="post" action="login.php" data-ajax="false">
<label for="username" >Username:</label>
<input type="text" id="username" name="username">
<input type="submit" data-inline="true" value="Submit">
</form>

html form post gives empty array

I am trying to post data from html form (html code is inside index.php file) into add_student.php file which is supposed to just print $_POST array using print_r function. But there is always empty array on result.
index.php
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" href="css/font-awesome.css">
</head>
<body>
<div class="contact col-md-12" id="get_in_touch">
<div class="col-md-10 col-md-offset-1">
<div class="contact_title">
<h2>
Add a student
</h2>
</div>
<div class="contact_container">
<div class="contact_form col-md-8">
<form action="add_student.php" method="post">
<input name="student_name" type="text" placeholder="FULL NAME" class="input1"/>
<input name="student_email" type="text" placeholder="E-MAIL" class="input1"/>
<input name="password" type="text" placeholder="PASSWORD" class="input1"/>
<input name="major" type="text" placeholder="MAJOR" class="input1"/>
<input name="group" type="text" placeholder="GROUP NUMBER" class="input1"/>
<input name="submit" type="submit" value="ADD STUDENT"/>
</form>
</div>
</div>
</div>
</div>
</body>
add_student.php:
<?php
print_r($_POST);
?>
Why I always get empty array?
It seems that problem is in PHPStorm localhost port. When you just enter in browser the address of index.php it works perfectly. However when I run code from IDE it returns empty array.
Perhaps it will work if you use an include as the following:
include_once add_student.php;
And then use index.php as the form action. IF you later want to proceed to another page, add a header <url> at the bottom of the included script.
Make sure you check if the submit button has been pressed in the add_student.php script isset($_POST['submit'])
Data might get lost in the travel from to page

Do I have to write PHP code in my HTML documents AND include it on EVERY page or can I use an external file just like css/js?

Is this the way to write your PHP? I would like to know if I can use an external file to keep things seperated, as I like to be organised. Also do I need to store my entire content in the XAMPP folder in Windows(C:) or just the PHP files? Haven't been able to find a decent answer on these questions. Help greatly appreciated.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="pagestyling.css">
</head>
<body>
<?php
include('/path/to/file.php');
?>
//scripts go here
</body>
</html>
EDIT EXAMPLE:
<?php
//form validation code here
?>
<div id="content">
<form class="applyform" method="POST" action="">
<h3>Please fill in your application below.</h3>
<p>
<label>In-game username:</label>
<input name="username" type="text"></input>
<h6>*Including CAPITALISED letters (if you have it)</h6>
</p>
<p>
<label>Irl Nickname:</label>
<input name="nickname" type="text"></input>
<h6>(So we know what to call you)</h6>
</p>
<p>
<label>Game:</label>
<select name="selectgame">
<option value="Heroes of Atlan">Heroes of Atlan
<option value="Knights and Dragons">Knights and Dragons
</select>
<h6>(What game do you want to join us in?)</h6>
</p>
<p>
<label>Email Address:</label>
<input name="emailaddress" type="text"></input>
<h6>*Used for GroupMe and confirmation email.</h6>
</p>
<p>
<label>Level:</label>
<input name="charlevel" type="text"></input>
<h6>(Your main character level)</h6>
</p>
<p>
<label>Arena rank:</label>
<input name="arenarank" type="text"></input>
<h6>(E.g. Heroes of Atlan: (1) 3358 or K&ampD: RIBBON E)</h6>
</p>
<p>
<label>Referral code:</label>
<input name="refcode" type="text"></input>
<h6>(Knights and Dragons only, e.g. "XU5-CP3-SK9")</h6>
</p>
<h5>Please check that the information that you have entered is correct before proceeding.</h5>
<input id="submitbutton" name="applySubmit" type="submit" value="Submit"></input>
</form>
</div> <!-- end of content -->
make a php file like this
include_file.php
<?php
//some php code
?>
some html here
now you can include it in every page you require. like this
<?php
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="pagestyling.css">
</head>
<body>
<?php
include("include_file.php");
?>
</body>
</html>
you can also use include, require, require_once or include_once as per your requirement.
and learn tutorial
Usualy you would write for exempe the header in the seperate header.php file and then include it in your main file:
<?php include('header.php'); ?>

php/jquery-mobile: Second page not running validation on two page form

I'm new to php and am trying to make a very simple two page form. Any help or guidance would be very appreciated!
Problem:
The second page does not run error validation when coming to it from the first page.
Both pages run error validation correctly URL's entered directly
Setup:
Page 1 one is HTML. It POSTS to Page2.
Page 2 is php and the data from Page 1 is stored in an input field
Live example:
http://www.linplusg.com/page1.html
In IE the Page 2 URL after coming from Page 1 looks to be incorrect:
http://www.linplusg.com/page1.html#/page2.php
In FF and Chrome the URL looks fine but I think there's a flicker/refresh happening.
Does something else happen besides just opening the page when doing a POST to a page? Does something value get stored the new fields? Am I doing the form action wrong? Dazed and confused...
Thank you so much for any help or suggestions. I've been searching around for answers all night and my brain feels like jello. It seems like I'm missing something simple?!
Page1 Code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
</script>
<script>
$(document).ready(function(){
$("#initialForm").validate();
});
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-role="content">
<form id="initialForm" method="post" action="page2.php">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="textinput3">
Zip Code
</label>
<input name="zip" id="zip" maxlength=5 value="" type="text" class="required" />
</fieldset>
</div>
<input type="submit" data-theme="e" value="Submit" />
</form>
</div>
</div>
</body>
</html>
Page 2 code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>
</title>
<link rel="stylesheet" href="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.css" />
<link rel="stylesheet" href="css/my.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.mobile/1.2.0/jquery.mobile-1.2.0.min.js">
</script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.10.0/jquery.validate.min.js">
</script>
<script>
$(document).ready(function(){
$("#fullForm").validate();
});
</script>
</head>
<body>
<!-- Home -->
<div data-role="page" id="page1">
<div data-role="content">
<form id="fullForm" method="get" action="">
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<input name="zip" id="zip" value="<?php echo $_POST["zip"]; ?>" type="" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="textinput3">
First Name
</label>
<input name="first_name" id="first_name" placeholder="" value="" type="text" class="required"/>
</fieldset>
</div>
<input type="submit" data-theme="e" value="Submit" />
</form>
</div>
</div>
</body>
</html>
To prevent this you need to specify data-ajax="false" in the form element in page1.
<form id="initialForm" method="post" action="page2.php" data-ajax="false">
see http://jquerymobile.com/test/docs/forms/forms-sample.html for more information.
Without the PHP code, I can just guess, but maybe it is because in the second form you have a method="get" instead of method="post", and in PHP you check the $_POST variable?
You could preserve the ajax transitions and still have your javascript execute on your second page by moving your script inside the div with the data-role "page".
See this answer here: https://stackoverflow.com/a/6428127/2066267

Java script stops after printing in php?

When the form is submit my jquery accordion stops working my file name is add.php here is its code
<?php require_once('database.php');?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<link rel="stylesheet" href="css/accordionTheme.css">
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery.ui.core.js" type="text/javascript"></script>
<script src="js/jquery.ui.widget.js" type="text/javascript"></script>
<script src="js/jquery.ui.accordion.js" type="text/javascript"></script>
<script>
$(function() {
$("#myAccordion").accordion();
});
</script>
<head>
<body>
<div id="myAccordion"><!-- Start Accordion --->
<h2>
Add Student
</h2>
<div>
<form action="add.php" id="form1" method="get" >//here my form start
<p>Please add Student Data</p>
<label for="stname">Enter Student Name:</label>
<input name="stname" type="text" id="stname" size="37" />
<br /><br />
<label for="stclass">Enter Student Class :</label>
<select name="stclass">
<option>MPhil</option>
<option>M.Sc.</option>
</select>
<br />
<input name="Add" type="submit" id="Add" value="Add" />
</form>
<?php
//lets start submit data to database
if(isset($_GET['stname'])&& isset($_GET['stclass']))
{
$stname=$_GET['stname'];
$stclass=$_GET['stclass'];
if(mysql_query("insert into student(teacher_id,student_name,student_class) values ('1','$stname','$stclass')"));
{
print "<p>record added</p";
}
}
?>
</div>
<h2>
Add course
</h2>
<div></div>
<h2>
Add publication
</h2>
<div></div>
</body>
</html>
I am printing php inside body you can see recordadded when form is submitted.
The p tag you print using PHP is not closed, which is what makes JavaScript go crazy. Close it and it should work OK.

Categories