I have a page ( index.html ) with a form. On submit the data is posted to a php-file which then stores said data in a (temporary) xml-file, however, I also have a number of iframes which also contain forms.
At first, I was planning on simply posting the input-data from the iframes to a seperate php file but I encountered several problems:
-I have several iframes, but I don't have a fixed amount since the user is supposed to be able to delete/ add iframes. Therefore I can't just tell iframe 1 to send its data to php-file no. 1, iframe 2 to send its data to php-file no.2 etc.., I need a flexible solution.
-I tried to submit all iframe inputs to ONE php file and was hoping it'd work since the xml-file this php-file sends the data to is only updated and not completely overwritten. As you might guess, this did not work.
-Another problem I encountered is that the user may go back and edit whatever he entered into the iframe. The data should only be saved once he clicks on the save button in the html-file to prevent that.
I also tried submitting the data via JavaScript, as people in similar questions suggested, but that did not work out for me. So I guess what I would like, is a suggestion as to how I should go about this. How can I send all the data once the "main" save button is clicked, it doesn't matter if the data goes to several php files. The solution shouldn't depend on a fixed amount of elements as that amount is not always the same.
Here's the iframe-html:
<form method="POST" action="php/iframe.php">
<label>Your thoughts:</label>
<input type="text" name="header">
<label>Suggestions:</label>
<textarea type="text" name="textbox"></textarea>
<input type="button" value="submit">
</form>
(It's basically the same for all Iframes).
Please let me know if you need any additional information.
Edit: I read that submitting forms at the same time may cause interference, I know that much
Edit:
Relevant index.html:
<form method="post" action="main.php">
<div id="firstSection"
<label>First input</label>
<input type="text" name="input[]">
<button type="button" onclick="openIframe1()">Read more</button>
</div>
<div id="secondSection"
<label>Second input</label>
<input type="text" name="input[]">
<button type="button" onclick="openIframe2()">Read more</button>
</div>
<button type="submit" value="submit"></button>
</form>
<div class="iframe">
<button type="button" class="close">Close</button>
<iframe src="iframe1.html"></iframe>
</div>
<div class="iframe">
<button type="button" class="close">Close</button>
<iframe src="iframe2.html"></iframe>
</div>
Define an array of your iframe inputs in the main page as hidden element, on click submit in the main page loop through the iframe by getting the datas and append to your hidden element from where you can now post that to your back end.. try this: Access jQuery data from iframe element
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 am using a simple HTML to post. It works well but sometimes randomly would not post. I have deduced that it when the user clicks on the font-awesome icon. When a user clicks on the button in an area outside of the icon, the form functions correctly.
I have tried using span but that doesn't made a difference.
<form method="post" target="votar">
<label>Subject</label>
<input id="subject_input" name="subject_input" type="text">
<label>Message Body</label>
<textarea id="body_input" name="body_input"></textarea>
<button id="submit_btn" name="submit_btn" type="submit"><i class='fa fa-paper-plane'></i></button>
</form>
If it helps, I'm also using this PHP to send the form.
// Get data from form
$body_input=isset($_POST['body_input'])?$_POST['body_input'].'body append':'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input'].'sub append':'';
// Loop sending a message for each recipient
foreach(array_column($user_ids, 'user_id') as $user_N) {
send_msg($user_N, $body_input, $subject_input);
}
try
var_dump($_POST);
and check, maybe an error here:
target="votar",
i don't see an isset post for your button
if(isset($_POST('submit_btn')){
$body_input=isset($_POST['body_input'])?$_POST['body_input'].'body append':'';
$subject_input=isset($_POST['subject_input'])?$_POST['subject_input'].'sub append':'';
}
you can add your foreach in as well where it needs to be
I have a page that has multiple php forms that send me different informations depending on the user and the form. How do I make php differentiat these? I saw something about the actions and I thought maybe it was like having a separate file, but when I created a "questions.php" and copied and pasted my php code into that and then added "action="questions.php"" to the tag, and ran it just as I had before it didn't work. So what is the correct way to do this?
My code is extremely long and filled with words which is why it would be nice to have separate files for it depending on the form instead of all in the top of my main page.
You could build one page as a standard page. in this page you could include the different forms. See the example below:
<!-- These are just example names -->
<div class="form-1">
<?php include "forms/form-1.php"; ?>
</div>
<div class="form-2">
<?php include "forms/form-2.php"; ?>
</div>
<div class="form-1">
<?php include "forms/form-3.php"; ?>
</div>
If you would like to save data that a user puts in a form in lets say a database you should use the <form method="post"> by adding an action to it. You're asking the form to send the user to another page when the submit button is clicked. an example of a form down below.
<form class="form-1" method="post" action="second_page.php">
<label>Name:
<input type="text" class="input" name="name">
</label>
<label>Email:
<input type="email" class="input" name="email">
</label>
<button type="submit">Send!</button>
</form>
Hope this helps!
I just added a / before the questions.php. apparently it had to do with file path? I don't understand it but it works now.
<form action="questions.php" method="post">
<!-- text boxes to get user inputs-->
<button type="submit" value="submit_btn">click here to go to page in action tag
</button>
</form>
If questions.php file is in same folder action="questions.php" is enough. If its inside 'x' folder, correct path should be given as action="x/questions.php"
i was making a website with PHP,jQuery,AJAX,mySQL which has lot of interaction with user. Now what i was asking that using forms are really necessary ?
what i have done for most of my user inputs are kinda like this -->
simple e.g
<div class="contact-form">
<input type="text" class="textInputs" id="name" placeholder="Enter your name..." />
<button class="submitButton" id="contactSend">Subscribe</button>
</div>
A SIMPLE comment system
<div class="comment-box" d-id="1">
<input type="text" class="textInputs" id="comment" placeholder="Enter comment..." />
<button class="submitButton" id="comment">Comment</button>
</div>
<div class="comment-box" d-id="2">
<input type="text" class="textInputs" id="comment" placeholder="Enter comment..." />
<button class="submitButton" id="comment">Comment</button>
</div>
JQUERY kinda this->
$('#comment').click(function(){
var id = $(this).closest('.comment-box').attr('data-id');
//ajax stuff
}):
Therefore what i wanna ask is whether this kinda structure is good or gonna cause some serious problem ?
Are using <form>'s compulsory ?
If you are submitting form by clicking submit button and posting variable to other pages or the same page then tag is necessary
If you are using form tag to find input values to post using ajax is necessary
If you are using ajax and pulling input values using dom id to post via ajax form is not required, in this case you may also need to do javascript validation using dom ids
Ideally using tag is better and follows standard HTML structure.
It depends upon your requirement and how you going to use the form in your project.
If you have min. no of fields ( 2-3 fields ) in your form. You can directly manipulate the form fields using id or name with JQuery or JavaScript. Otherwise you should have form tag to manipulate the data with more fields in the form.
I would recommend to have form tag in your page to maintain the standard format and use form tag and Ajax submission with Jquery.
Note: Anyway if you are going to get form data using Jquery, better to use the following syntax to get the from values:
// To check the radio button
var isAnsChecked = $("input:radio[name=<FIELDNAME>]").is(":checked");
var radio-value = $("input:radio[name=<FIELDNAME>]:checked").val();
// get Text box values
var text-value = $("input:text[name=<FIELDNAME>]").val();
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.