Not calling Post Data - php

Im having trouble trying to call POST data on my page,
My form is...
<form method="post" enctype="multipart/form-data" action="getdata.php">
<input type="hidden" id="TimeToRenderHoursInput" name="TimeToRenderHoursInput" value="" />
<input type="hidden" id="TimeToRenderDaysInput" name="TimeToRenderDaysInput" value="" />
<input type="hidden" id="TimeToRenderYearsInput" name="TimeToRenderYearsInput" value="" />
<input type="hidden" id="ContentMinutesInput" name="ContentMinutesInput" value="" />
<input type="hidden" id="ContentMinutesSelector" name="ContentMinutesSelector" value="" />
<input type="hidden" id="PriorityInput" name="PriorityInput" value="" />
<input type="hidden" id="AvgFrameRenderTimeInput" name="AvgFrameRenderTimeInput" value="" />
<input type="hidden" id="AvgFrameRenderTimeSelector" name="AvgFrameRenderTimeSelector" value="" />
<input type="hidden" id="CoresInTestInput" name="CoresInTestInput" value="" />
<input type="hidden" id="EstPriceInput" name="EstPriceInput" value="" />
<input type="image" src="images/CONTINUE.jpg" style=" border:none; padding:0; width:206px; height:41px; float:right; display:none;" id="continue" />
</form>
and my php page which should get the data is
<?php
$quantity = $_POST['TimeToRenderHoursInput'];
echo $quantity;
?>
The values in my form are populated before its sent using Javascript...

Just remove "display: none" from:
<input type=image ... >
and it will work.
The accepted answer above works too, of course. Just thought I'd point out where you went wrong in your code.

write before closing the <form>
<input type="submit" name="submit" value="Postdata" >
or wrap you image with submit button
<button type="submit" name="postdata" id="postData">
<img src="images/CONTINUE.jpg" style=" border:none; padding:0; width:206px; height:41px; float:right; display:none;" alt="Continue" title="Continue"/>
</button>
and also debug by writing below on getdata.php
echo "<pre>";
print_r($_POST);
echo "</pre>";
one more thing : Just remove display: none from <input type=image ... > ( Thanks #johndodo)
Note: if you use image to submit a form then get the data using image name dimension like this ( $_POST['submit_x'] OR $_POST['submit_y'] )
<form >
<input type="image" name="submit" src="whatever" value="Continue">
</form>
<?
if($_POST){
print_r($_POST);
}
if($_POST['submit_x'] || $_POST['submit_y']){
echo "An image button was used";
}

Related

PHP passing a variable across pages

I am having issues with a piece of code in Joomla. It may be something to do with the plugin that enables the PHP but in case it isn't.
Page 1 has a form
<form action="/index.php/bridge" method="POST" name="postcode">
<div><input style="height: 50px;" type="text" placeholder="Enter Your Postcode..." /> <input type="submit" value="Get Started today!" /></div></form>
The text you input becomes the variable I want to pass over
On Page 2
<?php echo "test";
$postcode=1;
$poster=$_POST['postcode'];
echo $poster;
// You can place PHP like this
?>
Unfortunately, the postcode isn't echoed
Assuming nothing else is the cause of this error, try naming the input you are sending over to postcode:
<form action="/index.php/bridge" method="POST">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
In your PHP code you are echoing $_POST['postcode'] but you are not sending the same variable at the time of form submission from input attribute.
<form action="/index.php/bridge" method="POST" name="demoForm">
<div>
<input style="height: 50px;" name="postcode" type="text" "placeholder="Enter Your Postcode..." />
<input type="submit" value="Get Started today!" />
</div>
</form>
Try this
<form action="/index.php/bridge" method="POST">
<div>
<input name="postcode" style="height: 50px;" type="text" placeholder="Enter Your Postcode..." />
<input type="submit" name="submit" value="Get Started today!" />
</div>
<?php
if (isset($_POST['submit'])){
echo $poster = $_POST['postcode'];
}else{
echo $poster = 1;
}
?>

html form is being sent on reset button

I have a problem with the html form.
This is my code:
<form name="contactform" method="post" action="send_form_email.php">
<input id="first_name" type="text" name="first_name" size="30"/>
<input id="company_name" type="text" name="company_name" size="30"/>
<input id="email" type="text" name="email" size="30"/>
<input type="image" align="middle" src="images/accept.png" alt="Submit" /> <input id="reset" type="image" src="images/reset.png" alt="Reset" align="middle" />
</form>
when I click any of this images my form is sent. How can I make this reset picture to only reset and not to send the form.
Your reset button is not a reset button. It has type="image", it is server side image map.
When you click on a server side image map the form will be submitted and the coordinates you clicked on will be included in the data.
If you want a reset button that is an image use:
<button type="reset"><img src="..." alt="..."></button>
The image type is like a submit button.
You have to take type="reset" and style your button with css.
Use
<input type = "reset" value = "" class = "btnResetClass" />
Your, btnResetClass will have Css Setting for background image to be set by you.
You have to use type="reset".
This jsFiddle example would be better.
HTML:
<form id="contactform" method="post" action="send_form_email.php">
<div>
<label>
First Name: <input id="first_name" name="first_name" type="text" size="30" />
</label>
</div>
<div>
<label>
Company Name: <input id="company_name" name="company_name" type="text" size="30" />
</label>
</div>
<div>
<label>
Email: <input id="email" type="text" name="email" size="30" />
</label>
</div>
<input id="submit" type="submit" value="" title="Submit" />
<input id="reset" type="reset" value="" title="Reset" />
</form>
CSS:
#submit, #reset {
border: none;
width: 64px;
height: 48px
}
#submit {
background: url('images/submit.png')
}
#reset {
background: url('images/reset.png')
}

How to process multiple forms using one php script

I have multiple forms and I have one php script that I want to use to process these forms but when I click on submit for any of the forms...the script is processed by the number of forms with the submit button named 'submitForm' in this case, the alert will show 3 times instead of once! What am I not doing right?
NB. I hope this makes much sense?
html code
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
php script
<?php
if (isset($_POST['submitForm'])) {
echo('<script>alert("Form Submitted")</script>');
}
?>
when I click on submit for any particular form, it submits all the forms.
this is not true.
Once your forms have proper formatting, your browser will submit only current one.
(and PHP has nothing to do here)
however, whole page will be reloaded, if you mean that. That is okay - when you submit a form, a page is intended to reload. If you need another behavior, you have to explain your wishes.
Also note that none of your text fields being sent to the server as they have no names.
I guess the question I should be asking is, how do I pass a particular form to php instead of writing multiple php scripts to handle each form!!!
well, it seems you want to ask how to distinguish these forms.
add a hidden field into each
<input type="hidden" name="step" value="1" />
and then in PHP
if ($_POST['step'] == 1) {
//first form
}
if ($_POST['step'] == 2) {
//second
}
This submits one form of many to php. Copy, paste, test, and study.
<?php
if (isset($_POST['submitForm'])) {
print_r($_POST);
}
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
Using a,b,c,d for the first form, e,f,g,h for the second form and i,j,k,l for the third form and submitting the second form yields the following output:
Array
(
[A] => e
[B] => f
[C] => g
[D] => h
[submitForm] => Submit Form
)
#Jay
Actually its not hard.
Once you supply form names, your work is done. the DOM does the rest.
write one php block to do your functions (create/update/retrieve/delete)
Whichever button is clicked, by default it submits only the elements enclosed together with it.
if(!empty($_POST)){
if(isset($_POST['submit'])){
print "<pre>";
var_dump($_POST); // write your code here as you would
print "<pre>";
}
}
try this with your form above.
I know this is an old post but here's how I solve this very problem.
All you need to do is make sure the submit buttons in each form have different names. Eg:
<form action="" name="form1" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm1" />
</form>
<form action="" name="form2" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm2" />
</form>
<form action="" name="form3" method="post">
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="text" value="" />
<input type="Submit" value="Submit Form" name="submitForm3" />
</form>
Then, you simply check which form's submit button was pressed.
<?php
if (isset($_POST['submitForm1'])) {
echo('<script>alert("Form 1 Submitted")</script>');
} elseif (isset($_POST['submitForm2'])) {
echo('<script>alert("Form 2 Submitted")</script>');
} elseif (isset($_POST['submitForm3'])) {
echo('<script>alert("Form 3 Submitted")</script>');
}
?>
If you need dynamic forms, you may try below code. While statement can be changed to fetch data from DB and use foreach instead. Hope you know this.
Here, I used while($n<10) for 10 dynamic forms.
You can also use tag as below if you need separate form names.
<form action="" name="form<?=$n?>" method="post">
This will create separate form names such as form1, form2, etc but not necessary here.
<?php
if (isset($_POST['submitForm'])) {
echo '<pre>';
print_r($_POST);
echo '</pre>';
}
$n=0;
while($n<10) {
$n++;
?>
<form action="" name="form1" method="post">
<input type="text" value="" name="A" />
<input type="text" value="" name="B" />
<input type="text" value="" name="C" />
<input type="text" value="" name="D" />
<input type="Submit" value="Submit Form" name="submitForm" />
</form>
<?php
}
?>
Sample page with output when I click row 5..

Hold variables in php for submit

I have several html textareas on my site. Each has a submit button. When a user types in one of the textareas i need to know which textarea this is. These textareas are each assigned a number taken from a mysql database. I can get the numbers out of the database, but how can I make it so that when a user types in a textarea and clicks submit the submit form knows which textarea this is. Please ask to clarify if needed. I tried my best to explain the problem. thanks.
p.s. the submit button just performs a mysql set values query. I'm using php on my site.
for example: a textarea is assigned '3.' When i submit this form i need 3 to be sent into my mysql set values query.
Use a hidden input to store a reference for each form
<input type="hidden" name="database_reference" value="<?php echo $dbId; ?>" />
Then when you submit the form $_POST['database_reference'] gives you the database id.
<input type="hidden" value="5" name="which_one" />
so for example
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="1" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="2" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="3" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="4" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="5" name="which_one" />
<input type="button" />
</form>
UPDATE:
<?php
if ($_POST){
include("db_connection.php");
mysql_query("UPDATE table SET column = '".mysql_real_escape_string($_POST['text'])."' WHERE value = ".intval($_POST['value']));
echo "done";
}
?>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="1" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="2" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="3" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="4" name="which_one" />
<input type="button" />
</form>
<form method="post" action="">
<textearea name="text"></textarea>
<input type="hidden" value="5" name="which_one" />
<input type="button" />
</form>
Assuming you have multiple <form></form> tags set up, one for each <textarea>, I would just add a hidden input field in each form. For example:
<form>
<textarea />
<input type="hidden" value="1" />
<input type="submit" />
</form>
<form>
<textarea />
<input type="hidden" value="2" />
<input type="submit" />
</form>
You can flesh it out from there, but you get the idea.

problem with the get variable

this is my form
<form name="thumbnail" action="<?php echo $_SERVER["PHP_SELF"];?>?complete=true" method="post">
<input type="hidden" name="x1" value="" id="x1" />
<input type="hidden" name="y1" value="" id="y1" />
<input type="hidden" name="x2" value="" id="x2" />
<input type="hidden" name="y2" value="" id="y2" />
<input type="hidden" name="w" value="" id="w" />
<input type="hidden" name="h" value="" id="h" />
<input style="margin-top:7px;" type="submit" name="upload_thumbnail" value="Save Thumbnail" id="save_thumb" />
</form>
and on the page i have this
<?php
print_r($_GET);
if($_GET["complete"] == "true"){ ?>
<script type="text/javascript">
parent.jQuery.fancybox.close();
</script>
<?php } ?>
but the get is always nothing..why is that when i add ?complete=true to the string
i tried GET POST but nothing....any ideas on how to do this
It works for me...
Array
(
[complete] => true
)
<script type="text/javascript">
parent.jQuery.fancybox.close();
</script>
So you have a problem somewhere else.
Also, if you are going to use <?php echo $_SERVER["PHP_SELF"];?> for your form, change it to <?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> for security.
Otherwise, I may request index.php/"%20onsubmit="alert('xss');return%20false"%20bla=" which leaves your HTML looking like....
<form name="thumbnail" action="/stuff/euler.php/" onsubmit="alert('xss');return false" bla="?complete=true" method="post">
Maybe try === instead of ==
I would guess the string "true" gets evaluated as true (boolean)

Categories