I want to make a file when the link is clicked. Can I do this using PHP?
Click Here
Use a form to do this and when it is submitted direct it to the php script that will create the file.
<form method="post" action="/make_file.php">
<input type="submit" Value="Click here">
</form>
Related
i use a form in which i get a file from user and submit it with button and take the values to another page with help of post(method). On the other page i have some business to do with that file beside that i have another form on that page. Now i want when submit that form (as it execute the php self script) so i want beside the new values i get that same file again. i try different technique like putting the tmp name in a variable but that doesnot work and even i create another file button in the form of that page but i am unable to give it a value. In short i need idea how to get the file on submittion of that second page form which is send from first page ?
For simplicty let me show you an example so you understand my problem,
//the first page form
<form method="post" enctype="multipart/form-data" action="uploadExcelData">
<label for="csv_file">Upload CSV File</label>
<input type="file" id="csv_file" name="csv_file" />
<input type="submit" name="upload" class="btn btn-primary"
value="upload" />
</form>
//on submit it goes to another page which have this php code and html form
<?php
$file = $_FILES['csv_file']['tmp_name'];
if (isset($_POST['save'])) { // the second form on submit
echo $file; //this show nothing
}
?>
<form method="post" enctype="multipart/form-data">
<input type="submit" name="save" class="btn btn-primary btn-block"
value="Upload" />
</form>
keeping above code in mind i hope somebody will understand the problem and suggest me something but i just summarize my code too much the second form also have many combobox etc and also i tryed to have a second file tag in second form but the problem is i cant even assign the file value to it so that it is selected automatically.
i want to get the file as output which have that shitty excel data!!
I'm a noobie programmer and I wonder how to properly submit a form with javascript.
I made some test code to show you what I mean:
<?php
if (isset($_POST['message']))
{
echo $_POST['message'];
}
?>
<script>
function formsubmit()
{
document.getElementById('form').submit();
}
</script>
<form id="form" name="form" action="" method="post">
<input id="message" name="message" value="hello world">
<input id="submit" name="submit" type="submit">
</form>
Click me<br/>
<input type="submit" onClick="formsubmit()" value="Click me">
When you push the "submit" button inside the tags - the php code will echo "hello world".
When submitting the form with JS the values won't post to the page. What am I doing wrong?
Thanks in advance.
I've searched the whole afternoon for a solution, but cause of my lack of knowledge about programming I failed to find it.
Believe it or not, but the main problem lies here:
<input id="submit" name="submit" type="submit">
If a form contains an input element with name (or id) of submit it will mask the .submit() method of the form element, because .submit will point to the button instead of the method. Just change it to this:
<input name="go" type="submit">
See also: Notes for form.submit()
The smaller problem is here:
Click me<br/>
An empty anchor will just request the same page again before calling formsubmit(). Just add href="#".
The problem here is that the id and name of the input element on your form is called submit.
This will mask the submit function for the form. Change the name and id and you will be able to use javascript to submit the form.
try setting the href of the to '#'. I would guess what is happening is that by clicking on the link, it submits the form and immediately changes the url to the same page you are on cancelling the form submit before it has a chance to go.
Do anyone know how can I rewrite a URL in php for the submit action?
Example:
I have a code as following:
I call to the page by using the following link www.assignment.com (I have set the index to test.php) and test.php will display the following code.
<form action="test.php" method="post">
<input type="text" name="phone" value="">
<input class="submit_btn" type="submit" name="submit" id="submit" value="SUBMIT">
</form>
when I clicked on the submit button, it will post to test.php to do the action and the display the same input page. However once submit button been clicked, the url link will become www.assignment.com/test.php. any way that I can rewrite the url to www.assignment.com after submit instead of www.assignment.com/test.php?
If your test.php is run when http://assignment.com/ is loaded, you could just change the form target to:
<form action="/" method="post">
You could use header("Location: www.assignment.com"); at the end of your test.php script.
I have two submit buttons in a php page. Based on the submit button clicked, I wish to redirect user to different php page. How that can be done?
<form>
<input type="submit" value="Go To Page1.php">
<input type="submit" value="Go To Page2.php">
</form>
Assuming you don't have any shared input boxes, you can just do something like this, or use simple links.
<form action="http://example.org/Page1.php">
<input type="submit" value="Go To Page1.php">
</form>
<form action="http://example.org/Page2.php">
<input type="submit" value="Go To Page2.php">
</form>
If you have additional input elements, I suggest looking into this solution. Relevant code sample:
<input type="submit" name="submit1" value="submit1" onclick="javascript: form.action='test1.php';" />
Just use a set of a tags inside the form:
<form>
<!-- Other Inputs -->
<div id="redirects">
Go to page 1
Go to page 2
</div>
</form>
If you need to send certain information along with your redirect, keep your current form and have a condition at the top of your file:
<?php
// You will need to send the $_POST data along with the redirect
if(isset($_POST['submit1']))
header('Location: page1.php');
else if(isset($_POST['submit2']))
header('Location: page2.php');
// Continue with the page...
?>
To send the $_POST vars along with the redirect, check this other SO post.
You don't need a form for this, neither input fields. Use <a> tags instead. You can style them with CSS to look like a button if you want that.
I have a form and a div. I want the user to select an text file and hit submit and that will populate the div with the content of the file. I would like to do that without having to refresh the page.
<form action="action.php" method="post" enctype="multipart/form-data">
Click the "Choose File" button and browse for the file to import.<br /><br />
<input type="file" name="filelocation" value="Browse" /><br />
<input type="submit" name="submitform" value="Submit" />
</form>
<div id="filecontent">
</div>
There is no easy way to submit/upload the files via ajax. However, you can go for the jQuery Uploadify plugin to the trick for you.
Uploadify is a jQuery plugin that
integrates a fully-customizable
multiple file upload utility on your
website. It uses a mixture of
Javascript, ActionScript, and any
server-side language to dynamically
create an instance over any DOM
element on a page.
Theres is no easy way to do that, but u can use an Iframe with an ajax call to get your file to the server and work with it the normal ajax way
<form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
File: <input name="myfile" type="file" />
<input type="submit" name="submitBtn" value="Upload" />
</form>
look at target="yourhiddeniframe"
here is a complete howto:
http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
greetings