Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm tried to put ajax form in while element, but not work.
Probably can not be repeated id in ajax form.
<?php while(..){ ?>
<form id="cancel-server" action="process.php" method="POST">
<input type="hidden" name="task" value="cancel-server" />
<input type="hidden" name="serverid" value="<?php echo $row['sid']; ?>" />
<button type="submit" id="ah">
<i class="icon-remove"></i> Otkaži narudžbinu
</button>
</form>
<?php } ?>
jquery:
$('#cancel-server').ajaxForm({
success: function(result){
var result=trim(result);
if(result=='success'){
$.poruka('', 'Success!');
}else{
$.poruka('', result);
}
}
});
php:
case 'cancel-server':
$serverid = $_POST['serverid'];
query_basic("DELETE FROM `serveri_naruceni` WHERE `id` = '".$serverid."'");
echo 'success';
break;
try to use the following snippt of code :
<script>
function _Submit(form){
$('#cancel-server'+form.id).ajaxForm({ }););
return false;
}
</script>
<form id="cancel-server<?php echo $row['id']; ?>" action="process.php" method="POST" onsubmit="javascript: return _Submit(this);">
...
</form>
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I don't know PHP and have downloaded this code that works perfectly fine.
I add this code on top of any *.php file and it makes that page, password protected that only opens up if you type the password which in this case is 1234.
Now, I want to add 3 passwords instead of 1. I just don't know where to edit this code.
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
if($pass=="1234")
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
<?php
if($_SESSION['password']=="1234")
{
?>
<form method="post" action="" id="logout_form">
<input type="submit" name="page_logout" value="Logout">
</form>
<?php
}
else
{
?>
<form method="post" action="">
<div>Protected Content</div>
<br />
<input type="password" name="pass" placeholder="Type your password">
<input type="submit" name="submit_pass" value="Login">
<br /><br />
<div><?php echo $error;?></div>
</form>
<?php
}
?>
Where should I, add what, to be able to have 3 possible passwords?
For this, you may edit password checking line like this:
<?php
session_start();
if(isset($_POST['submit_pass']) && $_POST['pass'])
{
$pass=$_POST['pass'];
$available_passwords = ['12345','pass123','myOtherPassword'];
if(in_array($pass,$ava_passwords))
{
$_SESSION['password']=$pass;
}
else
{
$error="Incorrect Pssword";
}
}
if(isset($_POST['page_logout']))
{
unset($_SESSION['password']);
}
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
<html>
<body>
<?php
echo "Hello Wolrd!";
if(isset($_GET['submit'])) {
echo "hello";
}
else {
}
?>
<h2> Sending data onclick </h2>
<button name = "submit" id="submit" onclick="<?php echo $_SERVER['PHP_SELF']; ?>" > order </button>
</body>
</html>
This is the code how I am trying to work. On clicking the button the php script should be executed but nothing is happening.
You need to create a form with action blank or same page name and use GET or POST or REQUEST in form method. This will help you to send the data on the same page and you can use some PHP code to display the data in whatever format you want.
Try this:
<html>
<body>
<?php
echo "Hello World!"; // will print when we run the program
if(isset($_GET['submit']))
{
echo "Hello World"; // will print this after form submission.
}
?>
<h2> Sending data onclick </h2>
<form action="" method="GET">
<input type="submit" value="Order" name="submit">
</form>
</body>
</html>
<form action="" method="post">
<input type="text" name="inputField">
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])) {
echo "$_POST[inputField]";
}
else {
// Code here
}
?>
PHP is a server side language and the button on click event is on the client side. In your code the php code given inside the on click gets executed at the server side when the user requests the page and the output will be placed there.
The best way for doing what you need. Like submitting data to the same PHP page when the user clicks the button is to create a in html.
<?php
if(isset($_POST['submit']))
{
echo "Data";
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="submit" name="submit" value="SomeValue" >
</form>
Or the other way is use PHP Session variables
<?php
// BEST WAY TO PASS DATA BETWEEN PHP PAGES
session_start();
if(isset($_SESSION['YOUR_SESSION']))
{
echo "Session Data";
}
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
with this example I recap my problem:
The first time I execute this php page I want to echo "I have two buttons".When the user click buttons "next" or "next1" I want to echo "I already said I have two buttons" and not "I have to buttons" again.I proved also with hidden input text but it doesn't work. thk for help
<?php
if ($_SESSION['already_said'] == false ){
echo "I have two buttons". date('h:i:s')."<br>";
}
$_SESSION['already_said']=true;
if( isset($_GET["next"]) || isset($_GET["next1"])) {
echo "I already said I have two buttons". date('h:i:s')."<br>";
}
?>
<html>
<body>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>
Of course the important thing is to remember to put the session_start() at the top of any script that uses the session. In fact it is a good idea to put it in all your scripts even if a few dont use the session just to keep the session alive.
<?php
session_start();
$msg = "I have two buttons ". date('h:i:s')."<br>";
if (! isset($_SESSION['already_said']) ){
$_SESSION['already_said'] = true;
}
if( (isset($_GET["next"]) || isset($_GET["next1"]) ) && isset($_SESSION['already_said'])) {
$msg = "I already said " . $msg;
}
?>
<html>
<body>
<div> <?php echo $msg; ?></div>
<form name="form" method="GET" action="" >
<button type="submit" name="next">
<span class="label">Next</span>
</button>
<button type="submit" name="next1">
<span class="label">Next1</span>
</button>
</form>
</body>
</html>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
i want display all with session what i enter into input.. but only one shows .. i want display past results too with session.. here my codes;
<form method="post">
isim gir
<input type="text" name="isim" id="isim[]" />
<input type="submit" name="gir" value="sözler" />
</form>
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(isset($_POST["gir"])){
$isim=$_POST["isim"];
echo $_SESSION["name"]=$isim;
}
?>
Create a search_history session variable that contains an array of all the searches.
if (!isset($_SESSION['search_history'])) {
$_SESSION['search_history'] = array();
}
if (isset($_POST['gir'])) {
$isim = $_POST['isim'];
$_SESSION['search_history'][] = $isim;
}
session_start() should be placed first thing in your code, and if you want to print everything in the array of $_SESSION you can do:
echo "<pre>",print_r($_SESSION),"</pre>";
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
$sanitize_post = filter_input_array(INPUT_POST);
if(!empty($sanitize_post)){
$_SESSION['input'][] = $sanitize_post;
}
function reducer($acc, $val)
{
return $acc .= $val;
}
function allUserInput()
{
# Extract user input from session.
if(empty($_SESSION)) return;
foreach ($_SESSION['input'] as $key) {
echo "<li>".array_reduce($key, 'reducer', '')."</li>";
}
}
?>
<form method="POST">
<ul><?php echo allUserInput(); ?></ul>
<input type="text" name="isim" id="isim" />
<input type="submit" name="gir" value="sözler" />
</form>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to insert my form information into a database that is already created. So far I have:
<form action="insert.php" method="post">
Username:
Password:
Confirm Password:
<input type="submit">
if loops {
send alert and return back to form page; }
</form>
My question is: using this code, will the user information still be sent to the database file if the if loops are activated or will I need an exit statement after every if loop? (I do not want any information sent if the if loops are activated).
Thanks
You need inputs on your form:
<form action="insert.php" method="post">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
Confirm Password: <input type="password" name="confirm">
<input type="submit" name="submit">
</form>
Then on insert.php
if (isset($_POST['submit'])){
$Error = 0;
if (!isset($_POST['username'])){
$Error++;
}
if (!isset($_POST['password'])){
$Error++;
}
if (!isset($_POST['confirm'])){
$Error++;
}
if ($Error > 0){
echo "Error in HTML Validation";
exit;
}
// continue post verification here.
}
You can also validate your form in client-side and it is faster and reduces server load:
<form name="myForm" action="insert.php" method="post" onsubmit="return validateForm()>
Username:
Password:
Confirm Password:
<input type="submit">
</form>
And write a javascript for validating your form:
<script type="text/javaScript">
function validateForm()
{
//Here will be your validation logic
//if input doesn't meet your requirement then return false
var x=document.forms["myForm"]["email"].value;
if(x is not an email address)
return false;
}
}
</script>