Decoding ampersand (&amp) to normal - php

I am having problems creating add file form which if person wants, it redirects after submit to add new file, but when I try to do that it still redirects back to m=files because it shows ?m=files&a=addedit. I tried using html_entity_decode, but still it shows the same ?m=files&a=addedit what to do, here is my redirect?
<input type="hidden" name="redirect" value="<?php echo $new = html_entity_decode('m=files&a=addedit'); ?>" />

Not 100% sure what OP wants, but simply replacing &amp with & should solve the problem, I think.
<input type="hidden" name="redirect" value="<?php echo str_replace('&', '&', 'm=files&a=addedit'); ?>" />

Related

How to send a get form wthout losing get parameters

I have a form located at a url containing get parameters,my form is also using this method.When the form is submitted it rewrites the previos get parameters.
Is there a simple way to rewrite only my form parameters?
I have in mind a Javascript solution ,however I want to know if there is a simpler way?Using HTML/PHP perhaps?
As far as I know, u u are not interested in using JS, then using form's hidden element is only way u have like this-
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
<input type="hidden" name="country" value="Norway">
<input type="submit" value="Submit">
</form>
<p>Notice that the hidden field above is not shown to a user.</p>
The question is how u can use it with PHP, right?
The solution is here-
//In PHP
if( isset($_GET['fromPerson']) )
{
echo $fromPerson;
}
So combined HTML and PHP code will be like this (assuming a get element from prevous page is named fromPerson)-
<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
<?php
if( isset($_GET['fromPerson']) )
{
echo '<input type="hidden" name="country" value=".$_POST['fromPerson'].">';
}
?>
<input type="submit" value="Submit">
</form>
Lets say you get a parameter p1 from a get request, it should look like this:
http://server.com/?p1=123
In your form, you can add hidden fields that would have the same effect when you submit, like this:
<form method="GET">
<input type="hidden" value="<?php echo $_GET["p1"]; ?>" name="p1">
</form>
That way you can resend the variables as many times as you need.
I'm not sure I understand your question... Can you post your code?
I assume you mean something like this?
in index.php
<input type="hidden" name="id" value="<?php echo $id; ?>" />
in return.php
Edit

PHP form is not posting data

I have a form on an HTML/PHP page.
I have the same exact code on other pages on the site, and it works fine. I cannot figure it out.
Form:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="prize_id" type="hidden" value="<?php echo $prize_id; ?>" />
<input name="ContestEntry" type="submit" class="submit" value="Enter me in the Raffle!" />
</form>
I looked at the HTML source code, and the action populates the correct page, and $prize_id populates the correct info in the value.
PHP:
if(isset($_POST['ContestEntry'])){
//...code to enter data into form, irrelevent since it won't post anything anyway.
}
else {
echo 'Nothing posted from form';
}
"Nothing posted from form" always shows, and no data is being entered into the database. I've tried changing the form name to 5 different things, thinking maybe there was a conflicting name somewhere, but nothing works.
Any ideas?
If all you need to achieve is check whether the form is submitted or not, it's better to check that the request type is a POST:
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Process form
} else {
// Nothing posted!
}
Also change your submit button to:
<button type="submit">Submit</button>
and see what happens
The code you posted actually works for me.
But, if you still can't get it working, I would try checking to see if prize_id is set rather than the button. The PHP script is executed when the form is submitted.
Also, I would recommend that you don't use $_SERVER['PHP_SELF'] as the form action. According to https://stackoverflow.com/a/14093363/3593228, that can make it easy for attackers to insert malicious data. Instead, leave the action empty.
The if Condition is not working because you put it on Button, instead of this just make an hidden field in the form to check form is submit or not like as you already have one. Or make new for this form.
<input name="prize_id" type="hidden" value="<?php echo $prize_id; ?>" />
Consider adding what you're looking for as another hidden field:
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input name="prize_id" type="hidden" value="<?php echo $prize_id; ?>" />
<input name="ContestEntry" type="hidden" value="Enter me in the Raffle!" />
<input type="submit" class="submit" />
</form>

Fill HTML-textfield-value with PHP $_GET-parameter

I have a link like this:
/index.php?textfieldvalue=test123
This link navigates to a site with a textfield. If this site is opened, the default-value should be "test123". To do this i used the PHP $_GET-parameter "textfieldvalue".
My textfield looks like this:
<input type="text" value="<?php $_GET('textfieldvalue') ?>" required />
But the textfield is still empty....
(And $_GET('target') is not empty! I printed it for testing seperate out)
Please remove '&' After '?' and in input field write:
<input type="text" value="<?php echo $_GET['textfieldvalue'] ?>" required />

Arrays are not posting to php

HTML
<link rel="stylesheet" type="text/css" href="<?php echo CSS_URL ?>modal.css" />
<form id="postinfo" action="" method="POST">
<input type="hidden" name="technician" value="<?php echo $technician; ?>">
<input type="hidden" name="custnum" value="<?php echo htmlentities(serialize($customerNum)); ?>">
<input type="hidden" name="meternum" value="<?php echo htmlentities(serialize($meterNumbers)); ?>">
<input type="hidden" name="remcred" value="<?php echo htmlentities(serialize($remCreditArray)); ?>">
<input type="hidden" name="visitdate" value="<?php echo htmlentities(serialize($dateArray)); ?>">
<a href ="<?php echo PROCESS_URL; ?>create_maint_token_excel.php" onclick="document.getElementById('postinfo').submit();">
<img src="<?php echo IMAGE_URL ?>Excel.png" name="Print Excel" title="Print Excel" alt="Print Excel" /></a>
</form>
PHP
$customerNum = unserialize($_POST['custnum']);
$meterNumbers = unserialize($_POST['meternum']);
$remCreditArray = unserialize($_POST['remcred']);
$dateArray = unserialize($_POST['visitdate']);
$technician = ($_POST['technician']);
I have tried numerous ways of posting these arrays to a php page but the page keeps telling me that custnum, meternum, remcred and visitdate are undefined.
I have tried using a form action and post, I have tried to use a piece of javascript and I keep getting the same problem, why is this not posting?
I have also tried using $_GET instead of $_POST on php page to no avail.
<a href ="<?php echo PROCESS_URL; ?>create_maint_token_excel.php" onclick="document.getElementById('postinfo').submit();">
This will not work, the submit will go into nirvana and you will be taken to the PHP page without the variables. You are doing two requests at once and your browser will go to the one without the form variables.
Try changing your form to this:
<form id="postinfo" action="<?php echo PROCESS_URL; ?>create_maint_token_excel.php" method="POST">
And your Link to this:
<a href ="#" onclick="document.getElementById('postinfo').submit();">
This should submit the form correctly without following the link.
Alternatively use a propper <input type="submit" /> button, you can add the image to it with CSS.
Why don't you just use a form submit button, rather than making life complax with javascript? But first.. Debug, check what is actually in your hidden input.
Better would probably be to keep all these details on the server in a table called maintenance, and only pass the record ID to the webpage. A lot less info that the user can tamper with.
Also, you can just use a regulaer weblink to link to load the next page with the variables in the url (read GET), unless there is some input from the user which requires a form, which we do not see.
You should be trying as,
<?php foreach ($customerNum as $item): ?>
<input type="hidden" name="custnum[]" value="<?php echo $item; ?>"/>
<?php endforeach ?>
In php you could get as,
$customerNum = $_POST['custnum'];
And use,
<a href ="javascript:void(0)" onclick="document.getElementById('postinfo').submit();">
<input type="hidden" name="technician" value="<?php echo $technician; ?>">
<input type="hidden" name="custnum" value="<?php echo htmlentities(serialize($customerNum)); ?>">
<input type="hidden" name="meternum" value="<?php echo htmlentities(serialize($meterNumbers)); ?>">
<input type="hidden" name="remcred" value="<?php echo htmlentities(serialize($remCreditArray)); ?>">
<input type="hidden" name="visitdate" value="<?php echo htmlentities(serialize($dateArray)); ?>">
<a href ="<?php echo PROCESS_URL; ?>create_maint_token_excel.php" onclick="document.getElementById('postinfo').submit();">
<img src="<?php echo IMAGE_URL ?>Excel.png" name="Print Excel" title="Print Excel" alt="Print Excel" /></a>
just replace to inpuit type submit or you can use type image and add action url to action tag of form then you would get values by post method like below exa
Here's a simplified test case:
<form id="postinfo" action="" method="post">
<input type="hidden" name="foo" value="1">
Submit
</form>
If you hit "Submit" you'll see that your browser will open the href URL before your JavaScript code has any chance to make a POST request to the action URL.
You'll possibly want one of these:
<!-- No action href -->
Submit
<!-- Cancel click event -->
Submit
<!-- No link at all -->
<div onclick="document.getElementById('postinfo').submit();">Submit</div>
Side note: If you use PHP serialization, beware of object injection.

Submit a form using anchor tag to open pdf in new window

I have a JQM-site that generates a pdf-file when submitting a form. All that is working fine, but I have a problem with the pdf not opening in a new window(open safari..) when started from home screen on iPhone.
It seems that I'm not the only one having problem with this, but I havn't found a working solution yet. I have no problem opening a new window in safari if I link to a static pdf with an anchor tag. My conclusion is that if I submit my form with an anchortag everything will work..!
However when i try with the following code the result is just the same as if I post my form with a regular submit button.
Can anyone please help me with another solution? Or maybe tweak this so that it works?
This is my form:
<form name="pdf" action="pdf_report1.php" data-ajax="false" target="_blank" id="pdf_report" method="POST">
<input type="hidden" name="customer_id" value="<?php echo $customer_id; ?>" >
<input type="hidden" name="date_from" value="<?php echo $date_from; ?>" >
<input type="hidden" name="date_to" value="<?php echo $date_to; ?>" >
<input type="hidden" name="user_id" value="<?php echo $user_id; ?>" >
<input type="hidden" name="maskin_id" value="<?php echo $maskin_id; ?>" >
<input type="hidden" name="akeri_id" value="<?php echo $akeri_id; ?>" >
<input type="hidden" name="littra_id" value="<?php echo $littra_id; ?>" >
Create PDF
</form>
Be sure to put these line into pdf_report1.php
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="downloaded.pdf"');
I don't know much about doing it with iPhone, but adding the target = '_blank' should force it to open in a blank tab or page, depending on the default for that broswer. EX:
Create PDF
After looking into this problem and not being able to solve it as I wished using the form, I went a different way.
Instead of using the form I simply just added all the values I needed in the URL and extracted it using get on the target page. Maybe not the most elegant way to do it but it works for me.
Now the PDF opens in a new window in safari when the web app is started from the home screen on iPhone just as I wanted.

Categories