form input box to download files [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Developing a school website in WordPress and need to upload Progress Report of students in the server in pdf format. File name of Progress report will be the Admission number of the students (Eg. 123.pdf). When students enter their Admission number in the input box, they should get their progress report file downloaded. As of now using below form box to redirect to file url.
<script>
function process()
{
var url="http://demo.websign.in/" +
document.getElementById("url").value;
location.href=url;
return false;
}
</script>
<form onSubmit="return process();">
ENTER YOUR ADMISSION NUMBER: <input type="text" name="url" id="url">
<input type="submit" value="DOWNLOAD">
</form>
Any help as I am a theme developer and no much knowledge in coding?

You do not need form tag to download file. Also instead of type "submit" use "button". The js you need is something like this:
function myFunction()
{
var downloadUrl = document.getElementById("url").value;
document.getElementById("downlod").href = downloadUrl + '.pdf';
}
<div>
<label>ENTER YOUR ADMISSION NUMBER:</label> <input type="text" name="url" id="url" onkeypress="myFunction()">
<a href="foo" id="downlod" download><span>Download</span></a>
</div>

Related

Display the value of form input [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a form with a input field like this:
<input type="hidden" id="name" name="name" value="">
Value of this input is changing trough some javascript function.
Now i would like to displays this value dynamicaly. For example:
<h1>This is the name: *input name value here*</h1>\
I know that you can use the value from different elements on a form when submiting, using the $_POST["name"]. But what about getting the value on same page dynamicaly.
<input type="text" id="name" name="name" value="" onblur="myFunction()">
<h1 id="fname"> </h1>
<script>
function myFunction() {
document.getElementById("fname").innerHTML = document.getElementById("name").value;
}
</script>

How to send data to another PHP file? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
There is a href tag:
Send
or a button (needs form tag)
<form action="file.php" method="GET">
<button type="submit">Send</button>
</form>
that will redirect to file.php URL.
I want to send id parameter to another PHP file. How do I do that?
==========================================================================
To send that data where must be provided input params (ex. hidden input) or in-url parameter.
ex.
<form action="file.php" method="GET">
<button type="submit">Send</button>
<input type="hidden" name="id" value="YOUR_ID"
</form>
or
Send
You want to transfer the id only to the next file? Use this in the first:
link_to_2
or
<form...>
<input name="id" type="hidden" value="1">
<button type="submit">btn_to_2</button>
</form>
And in your second file use this for both cases:
<?= $_REQUEST['id'] ?>

When I click in my newsletter subscribe button in my footer Im going to the top of my page [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
When I click in my newsletter subscribe button in my footer Im going to the top of my page.
I can have my sucess message my error messages but Im going always to the top of my page. And I dont want this because I want that usre see the feedback message without scroll down to my footer.
Do you see why this happening and how can I fix this?
<form action="" name="newsletter" method="post" enctype="multipart/form-data">
<div id="email_newsletter_container">
<input type="text" id="email" value="<?php if(isset($_POST['email'])) echo $email; ?>" name="email" placeholder="Insert your email..." required/>
<input type="hidden" name="newsl_sub" value="subscribe" />
<button class="btnn" type="submit" name="subscribe"><span>Subscribe</span></button>
</div>
</form>
When you put action="" the action will reload the page. If you put action="#newsletter" it should take the user to the section of the page that contains the form when the form is submitted. You may also want to add id="newsletter" to the form to ensure compatibilities.
<? if($post_was_submitted_and_comment_was_inserted) { ?>
<script>
window.addEventListener("load", function(){
document.getElementById("comments").scrollIntoView();
});
</script>
<? } ?>

php post to variable and then append to txt [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I'm having this problem where I can't manage to accomplish this simple script. Basically, I want to take a post from a form, assign it to a variable, and then append the variable to a preexisting example.txt file. I apologize for the lack of examples, I switched to my phone after I went out to dinner with my inlaws. Could anyone post a simple example andd allow me to build off of that foundation? thanks in advance
The following should give you a foundation to start.
<?php
// Check to see if the form was submitted
if(isset($_POST['action']) && $_POST['action'] == 'add'){
$file = 'example.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
$current .= $_POST['test'];
// Write the contents back to the file
file_put_contents($file, $current);
}
?>
<form method="POST">
<!-- This becomes PHP variable $_POST['test'] -->
<input type="text" name="test" />
<input type="hidden" name="action" value="add" />
<input type="submit" value="Add"/>
</form>
Check out http://us3.php.net/file_put_contents for more information.
If your html form has a text field like this
<input type="text" name="firstName" value="Name">
you can access that value in your php script using
$_POST['firstName'];.
If you want to append text in php, you can simply do it using "."
Ex: $post_string = 'Ex:' . $post_string;

PHP - Send a GET Parameter by POST with formvalue [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a problem, i will send a POST with PHP but i will
send a GET Parameter with the form value:
<form action="/Eventsuche/" method="post">
<table>
<tr>
<td>
<input id="Headsucheort" name="Headsucheort" type="text" value="" />
</td>
<td>
<button type="submit" name="Submit" id="Headsuchestart" value="Headsuchestart">»</button>
</td>
</tr>
So, on submit he bring me to /Eventsuche/ but i would like to
go here: /Eventsuche/Value of Headsucheort
Thanks! :)
<button onclick="window.location.href='/Eventsuche/' + document.getElementById('Headsucheort').value">»</button>
Didn't test but
If you really must do it in PHP, add this to Eventsuch:
if ( isset($_POST['Headsucheort']) ) {
header('location:http://www.your-url.com/Eventsuche/'.$_POST['Headsucheort']);
exit;
}
I see two ways to the that.
first:
you can add your variable to the end of your action value such as: action="Eventsuche?var=somevalue"
and second one would be:
as a hidden input and even tho it is hidden, php will capture it on submit as in:
<input type="hidden" name="myvar_name" value="my_var_value" />
i think this should do it.

Categories