Passing PHP form variables from one page to other - php

my php configuration on server are showing i can post variables to maximum size upto 8MB , thats enough .. but how to check for number of variables , sever is running ubuntu 4.4 , php .
i have a page which takes students marks and send them to a action page , but on action page doing echo for the post variables nothing is being displayed , where are doing an echo "hello"; this shows ...
this is the page which sends the variables
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable() ?>
<div class="mainframe">
<input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
and this are the variables are coming to action page .. but on echo they are not showing any value .
$dept =$_COOKIE['dept'];
$join=$_POST['batch'];
$type='e';
$sem=$_POST['sem'];
$chance=$_POST['chance'];

try placing this code on your action page:
if (isset($_GET)) {
echo "<h3>GET METHOD</h3>";
var_dump($_GET);
}
if (isset($_POST)) {
echo "<h3>POST METHOD</h3>";
var_dump($_POST);
}
if (isset($_COOKIE)) {
echo "<h3>COOKIE METHOD</h3>";
var_dump($_COOKIE);
}
See which method returns your variables and use it, otherwise, you are not filling any values on the form.

this is your code:
<form name="frm" action="marklistI.php" method="POST" class="" >
<?php $tb->displayTable(); ?>
<div class="mainframe"> <input type="hidden" name="batch" value="<?php print $_GET['batch']; ?>"/>
<input type="hidden" name="sem" value="<?php print $_GET['sem']; ?>" />
<input type="hidden" name="chance" value="<?php print $_GET['chance']; ?>"/>
<input name="submit" type="submit" class="hide" value="Save"/>
<input type="hidden" name="url" value="<?php print $_SERVER['REQUEST_URI']; ?>"/>
</div>
</form>
One possible reason for your issue:
You use "_GET[]" variables here but the form is POST.
GET and POST are two different methods to send data, GET is in the URL path (a=&b=&c=) while POST is hidden in the HTML headers.
So make sure you read those results as "$_POST['name']" and not GET.
I suggest this in the "receiving script" for debugging:
var_dump($_GET);
var_dump($_POST);
And in your browser use Chrome or Firefox + Firebug and Press "f12".
In that debugger you can catch the POST when you click the button and you can look which variables were sent.
That should help you debug your issue fast.
One other suggestion, I personally would write the code less "mixed".
It makes it hard to read and hard to modify.
Why not like this:
<?php
echo "
<form name='frm' action='marklistI.php' method='POST' class='' >".
$tb->displayTable().
"<div class='mainframe'>
<input type='hidden' name='batch' value='$_GET[batch]'/>
<input type='hidden' name='sem' value='$_GET[sem]' />
<input type='hidden' name='chance' value='$_GET[chance]'/>
<input name='submit' type='submit' class='hide' value='Save'/>
<input type='hidden' name='url' value='$_SERVER[REQUEST_URI]'/>
</div>
</form> ";
?>
My guess for your problem is that those values in the formular are actually empty, that's why you don't receive anything.

Related

PHP isset not accepting form name

I am having an issue trying to get my form with a hidden input field to be recognized when I check if it isset. Not sure if it is because I am running the form in a loop or what. I do know when I click submit for any of the fields from the loop the value of the hidden field is registering properly, it is just somehow the 'form1' is not registering as isset. Any ideas?
<?php
if(isset($_POST['form1']))
{
echo $_POST['cid'];
} else {echo "nope!";}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" name="form1">
// gets array
$listchars = $user->getCharacterList($_SESSION['user_id']);
// loops through array
foreach($listchars as $chardata){
echo $chardata['name']; ?>
<input type="hidden" name="cid" value="<?php echo $chardata['cid'];?>">
<input type="submit" name="submit" value="submit">
<?php } ?>
</form>
The form name is not submitted
Use
<input type="submit" name="form_name">
or
<input type="hidden" name="form_name">

values sent with POST/GET will not print as variables

I am working on a project to take two submitted variables and turn them into php variables (eventually they will multiply together) but as of now I cannot get the variables to be treated as such/echo.
I tried changing from POST to GET and the variables are sent through (appear in query line) but they don't print on the page
<?php
if (isset($_POST['submit'])) {
echo $_POST['length'];
echo $_POST['numPass'];
}
?>
<form method="post" action="">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit">
</form>
I expect that the variables will be echoed as a regular statement.
ie. length=2 and numPass=4
24
You can get the $_GET and $_POST request using $_REQUEST
if (isset($_REQUEST['submit'])) {
echo $_REQUEST['length'];
echo $_REQUEST['numPass'];
}
<form method="post" action="">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit" value="submit">
</form>
$POST['submit'] does not exist because your submit button does not have a name, it needs a name the same as your other inputs
It is better to check the input to avoid possible errors. You can try its example:
<?php
if( $_POST["length"] && $_POST["numPass"] ) {
echo "1: " . $_POST['length'] . "<br>";
echo "2: " . $_POST['numPass'] . "<br>";
echo $_POST['length'] * $_POST['numPass'];
}
?>
<form method="post" action = "<?php $_PHP_SELF ?>">
<input type="number" name="length">
<input type="number" name="numPass">
<input type="submit">
</form>

PLS HELP PHP syntax

Here's my form
<form id="place-bid" action="placebid.php?placeBidProductId='.$row['product_id'].'" method="post" >
Your Bid:<br>
<input type="text" placeholder="$$$" name="money">
<input type="Submit" class="button_bid" name="submit" value="Place Bid">
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
</form>
and here is my placebid.php
<?php
// $product_id=$_GET['placeBidProductId'];
$product_id=$_POST['row_id'];
echo " Id Produs : ".$product_id;
?>
My problem: I can't get the value from $row['product_id'], it will only echo the string "$row['product_id'] .$product_id;"
I'm guessing that before you are outputting that form you are doing some sort of query of a database. If that is the case then you likely want to change this line
<input type=hidden id='rowid' value=".row['product_id']." name='row_id'>
to
<input type=hidden id='rowid' value="<?php echo row['product_id'];>" name='row_id'>
Use print_r($_POST) for all form post value on form action page i.e. placebid.php. it will show you all value in form. Then make you business logic accordingly.

Form won't forward $score to next page

When a user takes a quiz, their score is captured in the value $grade, which displays fine on the quiz's home page. But if I change the form action to forward the user to a new page (grade.php), $grade loses its value.
How can I capture the value and display it on the next page? The values for PreviousURL and user_token display...
<form action="grade.php" method="post" id="quiz">
<input type="hidden" name="PreviousURL" id="url" />
<input type="hidden" name="user_token" value="<?php echo $_SESSION['user_token']; ?>" />
<input type="submit" value="Submit Quiz" />
</form>
So I tried this, but it doesn't work...
<input type="hidden" name="grade" value="<?php echo $_SESSION['grade'] ?>" />
on grade.php make sure to start the file with
session_start();
Based on your question, I assume that you did not start the session on grade.php. There is not much information about the file
If you don't start the session the values of $_SESSION get destroyed
You should not save form values in $_SESSION as form values are already in $_POST superglobal.
You can do it like
<form action="grade.php" method="post" id="quiz">
<input type="hidden" name="PreviousURL" id="url" />
<input type="hidden" name="user_token" value="<?php echo isset($_POST['user_token']) ? $_POST['user_token'] : '' ; ?>" />
<input type="submit" value="Submit Quiz" />
</form>
So basically it test if there is a value in user_token field it will apply that value other wise it will set to '' (nothing). If you are not familiar with the ternary operator syntax please refer to http://php.net/manual/en/language.operators.comparison.php
Updated Part:
// Your form page goes like
<?php session_start();
print_r($_SESSION); // If there is a session your form should show the value of user_token
// Rest of the script + html
?>
// grade.php
<?php session_start();
// do a print_r to see if you are receving session variables by
print_r($_SESSION);

Update form fields after posting with PHP_SELF

I am using php_self to submit a form. Once the data has been posted, I want to pass a calculated value to another form field on the same page, original form.
The $title_insurance field stays blank. Any ideas on why? Thanks!
<?php
if(isset($_POST['submit']))
{
$sale_price = $_POST['sale_price']; // posted value
$title_insurance = ($sale_price * 0.00575) + 200;
?>
<script type="text/javascript">
document.getElementById("title_insurance").value='<?php echo $title_insurance ; ?>';
</script>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input name="sale_price" type="text" id="sale_price" size="15">
<input name="title_insurance" type="text" id="title_insurance" size="15" value="<?php echo $title_insurance; ?>" />
<input name="submit" type="submit" class="bordered" id="submit" value="Calculate" />
</form>
The submit button is called button, also if you are outputting a javascript to amend the value it need to be run after the DOM has created the element title_insurance.
if(isset($_POST['button']))
{
$sale_price = $_POST['sale_price']; // posted value
$title_insurance = ($sale_price * 0.00575) + 200;
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input name="sale_price" type="text" id="sale_price" size="15">
<input name="title_insurance" type="text" id="title_insurance" size="15" value="<?php echo $title_insurance; ?>" />
<input name="button" type="submit" class="bordered" id="button" value="Calculate" />
</form>
<script type="text/javascript">
document.getElementById("title_insurance").value='<?php echo $title_insurance ; ?>';
</script>
A better way in this case would be to forget about the javascript as it is unnecessary and do this
// I am assuming you have initialized $title_insurance
// somewhere above here to its default value!!!!
$title_insurance = isset($_POST['button']) ? ($_POST['sale_price'] * 0.00575) + 200 : $title_insurance;
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input name="sale_price" type="text" id="sale_price" size="15">
<input name="title_insurance" type="text" id="title_insurance" size="15" value="<?php echo $title_insurance; ?>" />
<input name="button" type="submit" class="bordered" id="button" value="Calculate" />
</form>
You have an extra space in your getElementById parameter:
// VV
document.getElementById("title_insurance ").value='<?php echo $title_insurance ; ?>';
What you want to do is best done by AJAX. The <form> construction is outdated and not useful unless you are transferring the user to another page and sending some data along with it - or, if you are finished getting user data and just want to process what was entered and display a completion message.
If you wish to continue processing on the same page, then AJAX is the way to go. And the best way to use AJAX is to have a separate processor file (PHP) that receives the data, processes it, and sends it back.
To convert a <form> construct to AJAX, you really just need to remove the <form></form> tags and convert the submit button from type="submit" to type="button" id="mybutton", and use the IDs on the button and on the other elements to grab the data they contain and feed them to the AJAX code block. The examples in the link at bottom shows what you need to know - they are simple, helpful examples.
To conserve resources, you can use the same PHP processor page for multiple AJAX requests -- just send a variable (eg. 'request=save_to_db&first_name=bob&last_name=jones', ) and test for what "request" is received, that will determine what your PHP processor file does and echoes back.
This post, and the examples it contains, will help.
try this first
In you coding you missed this $_POST['button']
and
<?php
if(isset($_POST['button']))
{
$sale_price = $_POST['sale_price']; // posted value
$title_insurance = ($sale_price * 0.00575) + 200;
?>
<script type="text/javascript">
document.getElementById("title_insurance ").value='<?php echo $title_insurance ; ?>';
</script>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input name="sale_price" type="text" id="sale_price" size="15">
<input name="title_insurance" type="text" id="title_insurance" size="15" value="<?php echo $title_insurance; ?>" />
<input name="button" type="submit" class="bordered" id="button" value="Calculate" />
</form>
and also refer this FIDDLE it will more helpful to you..

Categories