how to use target in onclick event - php

Hi iam new to php and html ,here i have one resolution,i just upload a picture in database as well as upload folder.and i put download button also.the download button is working to download as same window.but i have to show in new window.please see my code.
<input type="submit" onclick='this.form.action="download.php"'
name="agreement" id="butt_down"
value="<?php echo _l('Dowload'); ?>" class="submit_button">
download.php
foreach($_POST as $name=>$value)
{
echo karthik;
if($value=='Dowload')
{
if($name=='agreement'){
$filename=$_POST['filename1'];
}
if($name=='invoice'){
$filename=$_POST['filename2'];
}
}
}
$baseurl='uploads/'.$filename;
header("Location:$baseurl");

Wrap your input in a form. This way you can remove the javascript completely
<form action="download.php" method="post" target="_blank">
<input type="submit" name="agreement" id="butt_down" value="<?php echo _l('Dowload'); ?>" class="submit_button">
</form>

Related

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.

How to call php variable input text from another Php page

My question is how do I call input value of user selected which has show by php code from another php.
Normal simple way we get the input this way
$calendar_id_val = $_GET['calendar_id'];
and now it is not working:
For example Show.php, I have one form which show the values from Database and show the result with php variable with While Loop.
<input name="calendar_id" value="<?php echo $calendar_id;?>">
and when user is submit that form I will carry these user selected value and perform insert.php
While you are doing echo in the input use echo $calendar_id_val
You should use form like,
<form action="insert.php" method="get">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>"/>
<input type="submit" name="submit_id" value="Insert"/>
</form>
Insert.php
echo $calendar_id_val = $_GET['calendar_id'];
Does this answer your question?
<form action="insert.php" method="GET">
<input name="calendar_id" value="<?php echo $calendar_id;?>">
</form>
If you want to redirect the user back to show.php, add this to the end of your insert.php script
header('Location: show.php');
exit();
I suggest $_POST var like this:
<form action="insert.php" method="POST">
<input type="text" name="calendar_id" value="<?php echo $calendar_id;?>" />
<input type="submit" name="submit" value="Submit" />
</form>
insert.php file:
echo $calendar_id = $_POST['calendar_id'];

Getting a php file in an iframe

I have two files one is index.php which contains a form which gets submitted to abc.php.Now the problem is have a frame in index.php where in i want to display the datas that i got after submitting the form to abc.php.I tried but m not able to it.Hope i hav mentioned all the thngs required. Any suggestion will be appreciated.
Set your form's target (phpfiddle demo):
<?php
if(!empty($_POST['submit_to_frame']))
{
echo htmlspecialchars($_POST['the_data']);
}
else
{
?>
<iframe id="the_frame" name="the_frame"></iframe>
<form method="POST" target="the_frame">
<input type="hidden" name="submit_to_frame" value="true" />
<input type="text" name="the_data"/>
<input type="submit" value="OK">
</form>
<?php
}
?>

'Upload' form to grab complete location of file?

I've created a HTML and PHP form to pretty much just input data into a MySQL table.
I've got a file upload field, but it doesn't upload a file. I don't want it to upload anything to the server, all I want is for it to grab the location of the file selected and input that into the database.
It works perfectly fine on Internet Explorer, but doesn't work on any other browser, I assume it's because of security issues it imposes.
My input code:
<input type="file" id="filename" name="filename" />
And of course when the form is submitted some PHP code runs through to insert the data into the database. I've tried JavaScript to copy value of that field to to another field but again because of security issues that doesn't work.
Does anyone know of a way I can do this in JavaScript? Or even Flash? To be honest, anything similar to these would do, just something that works in browsers other than IE.
Thanks.
EDIT -
Here's my code:
<?php
if (isset($_POST['submit'])) {
$name = addslashes(htmlentities($_POST['name']));
$filename = addslashes(htmlentities($_POST['filename']));
if (#mysql_query("INSERT INTO movies SET
name='$name',
doc_filename='$filename'")) {
echo '<p>Movie added.</p><p>Manage movies.</p>';
} else {
echo '<strong>Error:</strong> '.mysql_error().'';
}
} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="newspost" enctype="multipart/form-data">
<div class="form-row">
<label for="fm_title">Movie file path: </label><br />
<input type="file" id="filename" name="filename" />
</div><br />
<div class="form-row">
<label for="fm_title">Movie name: </label><br />
<input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />
</div>
<div class="form-row">
<input type="submit" name="submit" value="Submit" />
</div>
</form>
<?php
}
?>
all I want is for it to grab the location of the file selected and input that into the database.
This is no longer possible using HTML - for security reasons, the location of the selected file is not accessible in the file input's DOM element anymore. Most browsers use C:\Fakepath\ instead.
You might be able to get hold of this information using a Flash or Java based uploader (edit: see e.g. this page in the AS3 manual) SWFUpload's API could be worth a look. It could be that you need to build your own Flash or Java solution for this, though.
how you are posting the data of the form? I am not able to see any way of form post. No Submit button or onclick or onchange event of javascript? and also how you suppose this line to give output
<input type="text" class="input-width" name="name" value="<?php if (!empty($_POST['name'])) { echo $_POST['name']; } ?>" />
as its already in else part of the line
if (isset($_POST['submit']))

PHP APC Progress Bar

Post Updated: After commentors advice.
Index.php
<?php
$id = uniqid("");
?>
</head>
<body>
<form method="post" action="frame.php" target="upload_iframe" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $id; ?>"/>
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<iframe name="upload_iframe" style="width: 400px; height: 100px;">
</iframe>
frame.php
<?php
if(isset($_POST['progress_key'])) {
echo "hey1";
$status = apc_fetch('upload_'.$_POST['progress_key']);
echo $status['current']/$status['total']*100;
}
echo "hey2";
?>
Still doesnt work :(, I dont even get POST form data in frame. Where am i going so wrong?
Regards.
Whenever you use the APC file upload mechanism, you need to add an additional parameter to your form that identifies the file that's being uploaded, and is the key for your apc_fetch.
<?php $id = uniqid(time()); ?>
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="myUniProgressKey" value="<?php echo $id; ?>"/>
As the file is uploaded the value in the key upload . $id will contain the info you need to display the progress bar. Easiest way to get to is to ajax poll the server, using the apc_fetch call you have. This dictates that your upload page needs to not refresh the current page the user is on. I've used an iframe in the past that kicks off an interval to poll the server. Once the upload is complete, you're able to show a nice complete message in the same iframe.

Categories