I have a structure like :
<form id="first_form">
<fieldset>something</fieldset>
<fieldset>
<iframe><html> ...
<form id="second_form">
<input type="hidden" value="**some_value**" name="hidden_data" />
</form>
</html></iframe>
</fieldset>
</form>
What i need from this structure is to take the value from "hidden_data" in main form, and then to go post in database. I tried to prin_t($_POST); die; (after submitting first form) but i don't receive any input from second_form. Does somebody have an idea? Regards
Note : It's about wordpress plugin tdo mini forms
Note 2 : I want to get an url from an uploaded file (url which i get after i submit second_form) and then add as post meta, using first_form.
You can't just dump HTML inside of an iframe element. Any children of iframe are simply there to be displayed if the browser can't handle iframes.
Also, nested form elements doesn't validate (in HTML 4.01 Strict anyway, and I doubt in any others).
Why are you using an iframe with a form in it? Seems strange. And having HTML inside of that isn't what it is <iframe> tag is used for. Would be best to just have 1 form id="first_form" with the hidden element from the form id="second_form" in it. You can't put a form inside of another form, there can only be one at any given time.
Related
For example I have this line of html within form tags.
<form action="getData.php" method="post">
<div id="imadiv" value="2"></div>
</form>
How would I retrieve the value of the 'value' attribute so that I can use fwrite() to put it on a document using PHP?
Are you parsing html files that have this structure and need to access the value in order to create another document?
If not, then your form handler will have access to the value of "imadiv" (in this example) when you make your post.
if you were do do something like this
<form action="getData.php" method="post">
<input name="inputname" value="2"/>
</form>
and submit that form getData.php could do something like
$valueofinput = $_POST['inputname']
Giving your input tags a name attribute it important to reading the values out of the post payload.
If you're parsing HTML files with forms then I would suggest looking at XML/HTML parsing libraries that will help you access the html as a object node structure.
If you are doing something a little more complex where you want to validate the the data as the use enters, then you'll need to implement an ajax solution. However, keep in mind that connecting the post to key events can get messy as you could end up sending more requests than you originally wanted to if not implemented correctly.
My website is separated into two parts - a large (CodeMirror) <textarea> and a drop-down menu which has a <form> (that contains "From", "To", "Subject" inputs) in it linked to a send.php file.
The text area and the form itself are located inside different <div>s so I'm not able to link it to the rest of the inputs I'm transferring to the send.php file.
How can I link / connect the submit button to the <textarea> input along with the other inputs it's associated with ("From", "To", "Subject") when transferring the data to the send.php file?
<div id="container">
<div id="sidebar" class="twenty"> //the form div
<li class="menu">
<li class="dropdown">
<form method="post" action="send.php">
<input type=... />
<input type=... />
<input type=... />
<input type="image" src=... alt="Submit Form" />
</form>
</li>
</li>
</div>
<div class="seventy"> //the textarea div
<textarea id="code" name="code">
</textarea>
</div>
</div>
Technically, you could use the form attribute to associate a textarea with a form:
<form ... id="foobar">
...
</form>
...
<textarea form="foobar" ...>
This is an HTML5 feature supported by Chrome and Firefox, for example, but not IE 9.
So check out other options, primarily reorganizing the page as suggested by #niomaster or using JavaScript as suggested by #Fluffeh. However, it’s not a good idea to rely on JavaScript being enabled, in matters of basic functionality. In reorganizing the page, care should be taken to avoid messing up any styling (or scripting) that might rely on the current markup. Also note that the current markup is invalid, since li elements are allowed only as children of ol or ul, so restructuring (if feasible) would be recommendable anyway.
At the simplest, it might suffice to move the <form ...> start tag to the very start of the body element and the </form> end tag right before the end of the body element. Then all form field elements on the page would be fields of this form.
You can make form the outermost tag. It changes nothing to the flow of the document.
You can't directly - if it's not in a form, it can't be submitted.
The best you can do is to write a custom javascript function that replaces your 'submit (image type)' action and copies the data from the textform into a hidden field within the form then submits the form as the last action. This will get the results you want without the user really knowing what you are doing behind the scenes.
Edit: As niomaster correctly points out, forms can span more than just a single <div> or <li> attribute. You can extend it easily without changing your code structure.
use jquery
//Get the text from text area
var textareadata = $("#code").val();
//dynamically append a hidden feild to your form
$('form').append('<input type="hidden" name="myfieldname" value="myvalue" id='myvalue'/>');
// dynamically write your text adtea data to the hidden field append to the form
$('#myvalue').val(textareadata);
amiregelz,
You can just add one id to form tag. using jquery get the value of the text area [$("#text-areaID").val();]and add hidden field using jquery/ javascript, pass the value to hidden field which you created dynamically then after validation of the form submit the form. You can get the value of the textarea as well in your php page.
Hope It will help you. Please mark it answer if it helps.
How can I submit a form to itself without clearing the data in the fields using HTML, javascript and PHP?
You could take different approaches (e.g. cookies, jquery, etc...), however HTML + a line in PHP are more than enough in this case. Try this example code:
<form name="test" method="post">
Your Name: <input type="text" name="YourName" <?php if (isset($_POST['YourName'])) echo 'value="'.$_POST['YourName'].'"';?> >
<input type="submit" value="Submit">
</form>
In the code above if something has been posted to the receiving page (that can be the same page, such as in your case), then the posted value is printed out in the corresponding field. You can use this approach for all the fields composing your form.
If you want, you can also use similarly the $_GET method in the form.
If you use the traditional form submit, you need to save the parameters and rewrite the form input elements when you write the form the next time. But a better way is to use AJAX -- then the field data is sent without a form submission, and the input elements retain their data. See this link: http://www.w3schools.com/ajax/default.asp
I have the following form in a file called "foobar.html":
<!-- other stuff -->
<form method="post" action="foo.php?cat=1">
<input type="text" name="bar" />
<input type="submit" value="foobar" name="foobar" />
</form>
<!-- other stuff -->
And I open this file in a php script with fopen, how do I fill out and submit this form without any input from the user? Thanks
Parse out the action attribute with a HTML parser, and use curl to perform a POST to the appropriate target URL.
Read the entire fire into a variable. Rather than using fopen you might want to consider file_get_contents for that, it's a bit cleaner.
You'll then want to parse that string as HTML. You could use PHP's DOMDocument for that. Get the action and method of the form by traversing the DOM tree to the form tag and reading out those attributes. Next get the names of any inputs within the form tags. Use those names to generate a query string with your key=value pairs. If the method of the form is GET, then append that query string to the form action, otherwise save it in another variable.
Finally, use CURL to "submit" the form. That is, use the form action as the URL for a CURL request. If the form method was GET, you should have already appended the data to the URL, if the method was POST, you'll want to set the data for the CURL request to the data query string you generated from the form names.
If your question extend to how to know what data to fill into what form fields, that is pretty much impossible to solve. Certainly there are some input names you could look for and guess the required data but a universal solution is an impossible problem to solve.
Are you trying to have the user submit the form on their browser, without user interaction? If that's the case, you'll need to resort to javascript, something like:
<body onLoad="document.getElementById('autoSubmit').submit();">
<form id="autoSubmit">
(insert form here)
</form>
</body>
This will automatically submit the form. Some notes: not everyone has JavaScript enabled, so you might want to change the inputs to type="hidden", as well as add a nice big submit button that says Click Here.
$('#images_upload_add').click(function(){
$('.images_upload:last').after($('.images_upload:last').clone().find('input[type=file]').val('').end());
});
using this code to append file input's does not upload the file in firefox.
also
$('#image_server_add input[type=button]').click(function(){
var select = $(this).siblings('select').find(':selected');
if(select.val()){
$('#image_server_add').before('<tr class="images_selection"><td><input type="button" value="Delete"></td><td class="main">'+select.html()+'<input type="hidden" value="'+select.html()+'" name="images_server[]"/></td></tr>');
}
})
also does not upload the values to the $_POST
I can't find anything to say why this wouldn't work in the documentation, this works in IE but not it Firefox/WebKit
Why wouldn't these examples correctly upload the form values?
Bottom line the markup on the page was mangled.
The form was in a table based layout, not by my choice, and the form declaration was inside a tr.
I moved the form declaration to a parent td of the form inputs and now it works.
This is an interesting result considering the rendering engine will correctly submit inputs that are improperly placed, but attempting to add those inputs using jQuery/javascript? into the same place will not work in Firefox/WebKit.
I imagine this has to do with the dom manipulation that javascript does and how it may be more strict about the block level element requirements.
Any more notes/conjectures about my findings would be appreciated.
Are you having the same problem if you create a new input rather than cloning an existing one?
Are you changing the name of the cloned input to avoid name collisions or are you using an array style name (e.g. file[])?
What is the purpose of adding the markup of the selected option to a hidden input?
For fun, have you tried using .clone(true)?
Wow! Sometimes jQuery can actually be too dense to read. Would also help if we could see your markup.
Stab in the dark here because I'm guessing at what you're trying to do.
You can't programmatically enter a filename into a file field and it be uploaded to the server. That would be dangerous.
Perhaps I'm barking up the wrong tree?
Maybe rather than adding the element just as the form is submitted, put the element in, but with default values.
Then when the button is clicked, populate that element with the right value.
I just say that because by the time you click on the submit, it might be too late for the added element to be submitted along with the form.
I got to this section from google searching a similar problem.
To me, I was able to fix it by taking a step back at the problem -
in a example form:
<table>
<form method="post">
<tr>some content <input type="text" name="test"> </tr>
</form>
</table>
This will work in Internet explorer for some reason, but it is actually invalid html.
Move the form tags to outside the table, like so:
<form method="post">
<table>
<tr>some content <input type="text" name="test"> </tr>
</table>
</form>
And it will then work.
The input's will work fine (even dynamicly) this way, I was having a lot of trouble where a form would work, until you inserted more inputs or form elements - only the original elements would submit, which was very hard to track.