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
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 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
I have a button in my html form that I want it to take user to food.php when they click on it, I did this but it's not redirecting, Please help
<a href="food.php">
<button name="submit" type="button" id="food">Food - Equipment</button>
</a>
Try this:
<button>Food - Equipment</button>
Why use a button element inside a link tag? Why not just:
Food - Equipment
Try that and see if it fixes it.
A button is requested, not a link. Sometimes linked php files don't work as expected in some browsers. Use a form submit button and you'll get what you're looking for.
<form action="food.php" method="GET"> <!-- use get or post if you want
to send anything -->
<input type="submit" value="GO">
</form>
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.
I just started using twitter bootstrap, and I got stuck trying to get my form submit button to submit (PHP $_POST). Does anyone know why its not working?
No clue really..
I've been doing this previously and its been working until bootstrap:
<?php
if (isset($_POST["login"]) && $_POST["login"]=="login") {
echo "login here";
}
?>
<form action="http://mysite.com" method="post">
<input type="hidden" id="login" name="login" value="login" />
<button class="btn success" type="submit">Login</button>
</form>
The page seems to load but the PHP does not. Is the POST information being blocked?
My form input elements did not have an id or name (I didn't include them in my example).
Not an HTML expert, but I've always used <input type="submit" /> and not <button type="submit" />, not sure that button is a functional form element.
Also, your button element is closed twice - first with /> in the opening tag, and then again with a closing tag for no reason.
Maybe you are wrong with the action="http://mysite.com"? That attribute is for specifing the form data receiver, so in your case I think it's the page itself. So, if your page is named mypage.php, use action="mypage.php".
I had this same issue as well, turns out I was missing the name="submit". Gotta have that so the $_POST has a key in the assoc array!
it is adviseable that every element has a name thus (name="elementName") this makes it easy to reference them in your php scipt; also ensure that a form action and method are set.