problem with the get variable - php

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)

Related

Double Get Send Data

In this page : page.php?id=value
I've this html's code:
<form action="" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>
It's redirect me to: page.php?key=value , i want to redirect to: page.php?id=value&key=value , how i can do it? I must redirect it to this page with PHP ?
simply,
<form action="page.php" method="get">
<input type="hidden" name="id" value="<?php echo $value ?>">
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
You can have the id as a hidden input in your form
<form action="" method="get">
<input type="hidden" value="<?php echo $my_id; /*Suppose this variable contain your value */ ?>" name="id" />
<input type="text" name="key" />
<input type="submit" name="send" />
</form>
put everything you want on the next page in your form:
<form action="page.php" method="get">
<input type="text" name="id" value="<?php echo $_REQUEST['id'];?>" />
<input type="text" name="key" />
<input type="submit" name="send />
</form>
Really though, you should be using POST to send data, and the above code is NOT secure (allows anything in a url to easily end up in a form that could create some sql injection or XSS type issues.
You need to have the form's action set to the page you want it to submit to. If it is blank it will just submit to the same page.
<form action="page.php?id=value&key=value" method="get">
<input type="text" name="key" />
<input type="submit" name="send />
</form>

Passing Hidden Form Data in a session post

I have to submit this form to a payment processing gateway on my PHP page. All the credit card payment information will be taken on the next screen but the gateway needs the "HostedKey" and "Gateway_ID" need to be invisible from public code view as well.
<form action="nextpage.php" method ="POST" target="_blank">
Patient Account Number:
<input type="text" name="CustRefID" id="CustRefID">
<input type="hidden" name="HostedKey" id="HostedKey" value="ZZZZZZ" />
<input type="hidden" name="Gateway_ID" id="Gateway_ID" value="XXXXXX" />
<input type="hidden" name="IndustryCode" id="IndustryCode" value="2" />
<input type="hidden" name="Amount" id="Amount" value="" />
<input type="hidden" name="RecurringType" id="RecurringType" value="N" />
<input type="hidden" name="RecurringAmount" id="RecurringAmount" value="" />
<input type="hidden" name="CURL" id="CURL" value="back to my site" />
<input type="hidden" name="AVSRequired" id="AVSRequired" value="Y"/>
<input type="hidden" name="CVV2Required" id="CVV2Required"value="Y"/>
<input type="hidden" name="EmailRequired" id="EmailRequired" value="Y"/>
<input type="hidden" name="PostRspMsg" id="PostRspMsg" value="Y"/>
<input type="hidden" name="SECCode" id="SECCode" value="1" />
<input type="hidden" name="Descriptor" id="Descriptor" value="Online" />
<input type="Submit" name="Submit" id="Submit" value="Pay Online Now" />
</form>
I tried something like this. It hid the Key and ID but the form did not pass on the hidden session variables.
<strong>Patient Account Number: </strong>
<form action="nextpage.php" method"post">
<input type="text" name="CustRefID"/>
<input type="hidden" name="HostedKey" id="HostedKey" value="" />
<input type="hidden" name="Gateway_ID" value="<?php ($Gateway_ID); ?>" />
<input type="hidden" name="HostedKey" value="<?php ($HostedKey); ?>" />
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
if (isset($_POST['Submit']))
{ $_session['CustRefID'] = $_POST['CustRefID'];}
{ $_session['HostedKey'] = $_POST['xxxxxx'];}
{ $_session['Gateway_ID'] = "zzzzzz";}
?>
<strong><? echo $_session['CustRefID'];?></strong>
Any help would be great. My programmer is out sick...
You have repetition in your HTML. Change it to this:
<input type="hidden" name="Gateway_ID" value="<?php ($Gateway_ID); ?>" />
<input type="hidden" name="HostedKey" value="<?php ($HostedKey); ?>" />
2. You didn't specify what POST info should go in the SESSION. Change it to this:
{
$_SESSION['CustRefID'] = $_POST['CustRefID'];
$_SESSION['HostedKey'] = $_POST['HostedKey'];
$_SESSION['Gateway_ID'] = $_POST['HostedKey'];
}

php forms: value="<?php=$_POST['total_amount']?> vs. value="<?=$_POST['total_amount']?>

My form is generating an error when I use:
<input type="hidden" name="total_amount" value="<?php=$_POST['total_amount']?>" />
however it works fine when I use:
<input type="hidden" name="total_amount" value="<?=$_POST['total_amount']?>" />
I thought it was insecure to use <?= instead of <?php.
Here is the complete form:
<form name="save_file" action="cyprus_funds_transfer.php" method="post" enctype="multipart/form-data">
<? if($_POST['value_type'] == 1) {?>
<input type="hidden" name="amount" value="<?php=$_POST['account_number']?>" />
<input type="hidden" name="value_type" value="1" />
<input type="hidden" name="total_amount" value="<?php=$_POST['total_amount']?>" />
<? } else { ?>
<input type="hidden" name="amount" value="<?php=$_POST['amount']?>" />
<input type="hidden" name="value_type" value="0" />
<? } ?>
<input type="hidden" name="to" value="<?php=$_POST['send_to']?>" />
<input type="hidden" name="from" value="<?php=$_POST['send_from']?>" />
<input type="hidden" name="message" value="<?php=$_POST['message']?>" />
<input type="hidden" name="mode" value="save" />
<input type="hidden" name="order_id" value="<?php=$order_id?>" />
<input type="hidden" name="email_id" value="<?php=$_POST['email_id']?>" />
</form>
This is wrong way
<?php=$_POST['send_to']?>
this is correct way
<?=$_POST['send_to']?> is similar to <?php echo $_POST['send_to']; ?>
Codepad
Try to replace
<?php=$_POST['send_to'];?>
to this
<?=$_POST['send_to'];?>
or with this
<?php echo $_POST['send_to'];?>

Reading a form in wordpress with the plugin Exec-PHP

We are using the Exec-PHP to use PHP in our wordpress page. But we got a problem, we cant read from a textfield form. Is this a Exec-PHP limmitation (If so could anyone recommend a plugin who does allow this) Or is something wrong in our code?
This is our code:
<form action="" method="post">
<input type="text" value="voornaam" />
<input type="submit" value="Verzend" />
<input type="hidden" name="button_pressed" value="1" />
<?php
if(isset($_POST['button_pressed']))
{
echo $_POST["voornaam"];
echo 'Done';
}
?>
You should add:
<input type="text" value="voornaam" />
Then, in your PHP, you can use:
echo $_POST["voornaam"];
Your form:
<form action="" method="post">
<input type="text" value="voornaam" />
<input type="submit" value="Verzend" />
<input type="hidden" name="button_pressed" value="1" />
</form>

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..

Categories