HTML and PHP: Don't opening a new window in the browser - php

I have a file HTML with a lot of buttons, when I click a button, the action in the HTML is a reference to a php file.
What can I do for don't open a new the page, I mean run the PHP file without opening it.
This is the form in my HTML
<form action="Controlador.php" method="POST">
<p>He querido irme a dormir a las 8:00 en viernes</p>
<input type="submit" class="button" name="1" value="Vota" />
<br>
</form>

see this How do I make a PHP form that submits to self?
do not define separate action page, use same form page for action

Related

How to link a PHP file to a html button

I want to load a php file when the user clicks on the button, but it isn't working and php file is not loaded. Is there any way to link the php file to the button via anchor tag?
<a href="visual.php" >
<button name="visual" id="newbtn" >Add Visual device</button></a>
<a href="audio.php" ><button name="audio" id="newbtn" >Add Audio device</button></a>
I need to create a main html page which includes only two buttons and when "Add Visual device" button is clicked a php page is loaded with a form to add details about the device to visual device table in sql database. When the "Add Audio device" button is clicked it need to load the php page with form to send the data to the audio table in the db. But nothing loads when the buttons are clicked... I want to load the two pages when the respective buttons are clicked
here is the code to hit php file through anchor tag.
<html>
<body>
visit php file
</body>
</html>
here is the code to hit php file through button.
<form action="audio.php" method="get">
<input type="text" name="id">
<input type="submit" value="Open Form">
</form>
you can do it by adding onclick event as follows
<button onclick="window.location.href = 'audio.php';">Add Audio device</button>
<button onclick="window.location.href = 'visual.php';">Add Visual device</button>
//It can be useful when you are not using a <form> tag.

How to give one file uploaded value to input (file) tag on second page?

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!!

Making File when Href clicked

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>

Upload Progress bar within form data

I try to create an upload progress bar with PHP and jQuery. However, I have a problem when I bring it to the form data. The code is similar like this:
<form method="post" action="upload.php" enctype="multipart/form-data" id="upload-form" target="upload-frame">
Suburb:<input type="text" name="txtSuburb" id="txtSuburb">
Picture:
<input type="hidden" id="uid" name="UPLOAD_IDENTIFIER" value="<?php echo $uid; ?>">
<input type="file" name="file">
<input type="button" name="submit" value="Upload!">
<iframe id="upload-frame" name="upload-frame">
</iframe>
<input type="submit" name="DataSubmit" value="Submit Data"/>
</form>
As you can see, I got 2 submit buttons. If I keep the form like this then the form can't submit data to server. It just submits the file to iFrame. If I change the action and target of the form then the upload progress function will not work.
Could anyone please help me to find the solution for this?
I want the user can click on upload button to upload their file. Then they can take the rest to fill the form. When everything is done, they can click on another submit data button to submit their data (included the file) to the server.
Make sure that you have only one input element of type submit within your form.
If you want the first button to trigger some Javascript, use a regular input element or even a styled link and attach a Javascript event to it's onclick event, then prevent it's default behavior, e.g. by returning false.
Like this only the second button will actually submit your form which should do what you're describing.
In general I'd second #Treffynnon's suggestion to use a existing library for this purpose. These hacks have a tendency to get pretty nasty, especially when it comes to crossbrowser compatibility.

Unable to select dynamically generated form elements (ajax)

I have a main.php page
the following code is hardcoded in main form
<form action="test.php" method="POST">
the following is the code generated dynamically using AJAX
<input type="checkbox" value="test" name="test[]"/>
<input type="checkbox" value="test1" name="test[]"/>
<input type="submit" value="go">
ideally speaking on clicking the go button the page should submit to test.php page with the post value of the check elements
but now i find no action is taken by the browser. Also i find no error message in error console.
this used to work upto firefox 3.5 and IE 8. However in Firefox 3.6 the dynamically generated form elements are not recognized at all
Is there a mistake in the code and is a there a work around
Make sure that the dynamic content does not replace the form .. but gets appended to it (or replaces the contents and not the actual form tag..)

Categories