About passing referrer php - php

I know that this is answered but i cajnt find the answer...
I want to pass within a hidden field the value of $_SERVER["REQUEST_URI"]
I dont know how value in <input type='hidden' value=''/> should be echoed ..
It is sent through post... I tried using rawurlencode( $_SERVER["REQUEST_URI"])) but i have to do decode again... Is there any other solution ?

echo "<input type='hidden' value='" . htmlspecialchars($_SERVER["REQUEST_URI"]) . "' />";

Related

Hidden value requires to be send twice

Basically I make a calculation and use a hidden value to put it into an input field.
So I've tried to recreate my problem in the code below as to not give away the actual code I'm working with since it's a bit more sensitive.
The question is whether it's possible to get the hidden value inside the disabled box without having to click the send button twice.
If I'm asking the impossible just say so I'll figure something out.
<form action='test.php' method='post'>
<?php
#$result = #$_POST['number1'] * #$_POST['number2'];
echo "<input type='text' name='number1'>
<input type='text' name='number2'>
<input type='text' value='"; if(isset($_POST['value'])) echo $_POST['value']; echo"' disabled>
<input type=hidden name='value' value='" . $result . "'>"
?>
<br>
<input type=submit>
</form>
do you expect the $result in the disabled input if the $_POST["value"] is not set?
echo "<input type='text' value='" .(isset($_POST['value'])?$_POST['value']:$result)."' disabled>";

Trunction of string when using MySQL select

I pulling text that is stored in my database using MySQL select so it is displayed in a form so it can be edited.
When the form is set to the string held in the database gets truncated at the first space so "Foo Bar" would be displayed as "Foo". This doesn't happen when using the tag.
I have made sure that the text field is big enough to hold the entire string and the number of charters isn't limited.
In the database the whole word is stored and no truncation is happening. I set the type to varchar(30) which is enough space to store the whole word. I have also tried changing the type to text and I still have the problem.
I can't seam to find a solution anywhere does anyone have an idea of why this may be happening?
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\" value=" . $row["title"] . ">"; ?>
You should provide a sample of the HTML produced from your php page. Most likely, your value string is not being quoted, e.g. your HTML form looks like:
<input type=text value=Foo Bar>
instead of
<input type=text value="Foo Bar">
This would produce exactly the effect you are seeing
UPDATE: Based on your example in the comment, you are indeed missing the quotes:
Old code with the problem (missing quotes around value attribute's value):
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=" . $row["title"] . ">"; ?>
Fixed code:
<?php echo "<input type=\"text\" name=\"title[" . $row["id"] . "]\"
value=\"" . $row["title"] . "\">"; ?>
Note that you already had the name attribute correctly quoted, but value was not.
Without the relevant code, this is just a guess, but are you setting your form input value attributes without using quotes?
For example, are you doing this?
<input type="text" value=<? echo $value; ?> name="formInput" />
Instead of the correct syntax, which is this?
<input type="text" value="<? echo $value; ?>" name="formInput" />

Problem in sending values between pages in PHP

I want to send data from one page to the other via a form in PHP. In the initial page I have included the following PHP script that generates an input form with hidden fields. The names of these hidden fields are generated by the PHP:
<?php
echo "<form class='available-form' name='available_os' method='get' action='process-results.php'>";
echo "<input type='hidden' name='$software'></input>";
echo "<input type='hidden' name='$version'></input>";
echo "<input type='submit' name='available-button' value='Find Available Libraries for this Software'></input>";
echo "</form>";
?>
In the second page, named process-results.php, I would like to get the names of these hidden fields via the $_GET method but of course using $_GET[$software] and $_GET[$version] wouldn't work...Can someone tell me if there is a solution to this issue or if there is a better alternative? Thanks in advance
Instead of
"<input type='hidden' name='$software'></input>";
you should use
"<input type='hidden' name='software' value='".$software."'></input>";
for each. This way, you can use $_GET['software'] to retrieve the value. Do this for each of your hidden inputs.
I think you may want something like:
<form ... >
<input type="hidden" name="software" value="<?php echo $software ?>" />
<input type="hidden" name="version" value="<?php echo $version ?>" />
</form>
and then
$_GET['software'];
$_GET['version'];
I'm not sure what you're trying to accomplish, but this looks odd to me. Isn't the below code more of what you're looking for?
<?php
echo "<form class='available-form' name='available_os' method='get' action='process-results.php'>";
echo "<input type='hidden' name='software' value='$software'></input>";
echo "<input type='hidden' name='version' value='$version'></input>";
echo "<input type='submit' name='available-button' value='Find Available Libraries for this Software'></input>";
echo "</form>";
?>
That way you will get a query string in form of ?software=yoursoftwarename&version=yourversion and it will be available via $_GET["software"] and $_GET["version"] on the next page.
You could iterate over each of the items in the $_GET array on process-results.php. The problem is that the keys for the value will be whatever $software and $version are set to on the first page. Try something like this:
foreach($_GET as $key=>$string) {
// Do stuff with them
}
Add
enctype="multipart/form-data"
To the tag... so it looks like
<form enctype="multipart/form-data" method......
If you really need to have the dollar-sign inside the name, escape it:
echo "<input type='hidden' name='\$software'>";
or put the string in single-quotes:
echo '<input type="hidden" name="$software">';
Otherwise PHP is looking for a variable named "$software", if you look inside the browser-source you will see that the name-attributes are empty(except you're having those variables defined somewhere).

Form not passing any values

I have a form that I'm submitting using jQuery $.post(). It doesn't submit any variables.
Here's the jQuery code:
$('#eb1').live('click',function() {
$.post("php/emailPost.php", $("emailPost").serialize(), function(){
$("#emailModal").dialog('close');
$('#emailJQButton').attr('value', 'Emailed');
});
});
The post file returns no errors, and everything else is working fine. It's only the fact that no values are passed (I checked with Firebug).
Here's a portion of the PHP code outputting the form itself (don't say anything about HEREDOC, it does not work for me, case closed):
echo "<form action='php/emailPost.php' method='POST' class='inline' id='emailPost'>";
echo "<input type='hidden' value='" . $_SESSION["email"] . "' name='emailAddress'>";
echo "<input type='button' value='Email To Me' id='eb1'/>";
echo "<input type='hidden' name='passedCoupID' value='" . $coupID . "'/>";
echo "</form>";
I don't see anything obvious why it doesn't pass any values. Other similarly-written forms pass variables correctly. $coupID is pre-populated by the page.
Any help?
$("emailPost").serialize()
Should be
$("#emailPost").serialize()
change $("emailPost").serialize() to $("#emailPost").serialize() or $("form").serialize()

PHP SQL UPDATE works in FF and CHROME but not in IE?

the below code works perfectly in FF and CHROME but not in IE. Please help. I have commented out my santize functions as i thought they might be affecting it, but it still does the same.... nothing in IE.
Thank you in advance for any assistance.
<?php
//IF UPDATE BUCKET CHANGE STATUS...
if(isset($_POST['updatebucket'])){
$complete = $_POST["complete"];
$bucketid = $_POST["bucketid"];
//$complete = sanitizeone($_POST["complete"], "plain");
//$complete = strip_word_html($complete);
//$bucketid = sanitizeone($_POST["bucketid"], "plain");
//$bucketid = strip_word_html($bucketid);
if ($complete=="1")
$complete = "0";
else
$complete = "1";
$updatebucket = "UPDATE membersbuckets SET complete = '$complete' WHERE userid = '$userid' AND bucketid = '$bucketid'";
mysql_query($updatebucket);
}
?>
and the front end....
<? if ($complete=="1") {
echo "<form action='' method='post' name='updatebucket'><input name='complete' type='hidden' value=" .$complete. " /><input name='userid' type='hidden' value=" .$userid. " /><input name='bucketid' type='hidden' value=" .$bucketid. " /><input type='image' name='updatebucket' value='updatebucket' src='images/tick.png' /></form>";
}else{
echo "<form action='' method='post' name='updatebucket'><input name='complete' type='hidden' value=" .$complete. " /><input name='userid' type='hidden' value=" .$userid. " /><input name='bucketid' type='hidden' value=" .$bucketid. " /><input type='image' name='updatebucket' value='updatebucket' src='images/cross.png' /></form>";
}
?>
Dan
You should post your front-end, not back-end (since it's pretty much not browser-dependant).
Your HTML probably isn't valid.
Edit:
Yep, IE doesn't take value for image type of input. It only sends the x & y (field_name_x, field_name_y) and totally discards the original "value" attribute.
Try with a hidden input instead.
It seems that input type='image' doesn't send the value when used from IE. You'll need another hidden field:
<input type='hidden' name='updatebucket' value='updatebucket' />
<input type='image' src='images/tick.png' />
That way, the updatebucket parameter will be posted to the server, regardless of the browser used.
The assumption here was that all browsers handle HTML forms the same way (and they don't); that's why I keep Eric Lawrence's excellent Fiddler around - it can diff two HTTP requests, so you'll see the difference between the browsers immediately.
An alternative would be to check for $_POST[{image-element-name}_x}] (in this case $_POST['updatebucket_x']. All browsers will send the x/y coordinates of the image element as updatebucket.x & updatebucket.y, and PHP silently (and frustratingly) alters the updatebucket.x to updatebucket_x. Then again, you only need this is clicking different input type=submit / type=image elements would alter the action taken, otherwise the previous solution of a hidden element as previously suggested would do.

Categories