Posting problems with dynamical form using jquery - forms

I wrote a dynamic form using jQuery, basically like this:
<form action="" method="post">
<input type="radio" name="rgroup" value="1">small form
<input type="radio" name="rgroup" value="2">whole form
<input type="text" name="inp1">
<div id="formpart">
<input type="text name="inp2">
</div
<input type="submit">
</form>
And
$('input[type=radio][name=rgroup]').change(function(){
$('#formpart').toggle();
});
Visually everything works fine, but in my $_POST array, the input field inp2 does appear, but is always empty... What can I do about it?

Related

Combination: Open mailto and form submit

This combination of an open mailto window with a post form to test.php on one click does not work. Any suggestions?
<form id="myForm" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
<a href="mailto:..."
onclick="document.getElementById('myForm').submit();">
Submit
</a>
</form>
Check below solution to ignore href attribute and focus on using onclick only to do what you need
function submit() {
window.open('mailto:mail#example.org', '_blank');
document.getElementById('myForm').submit();
return true;
}
<form id="myForm" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
<a href="#" onclick="return submit();">
Submit
</a>
</form>
And if you need to use both href and onclick check below alternative solution
function submit() {
document.getElementById('myForm').submit();
return true;
}
<form id="myForm" action="test.php" method="post" onsubmit="alert('Ok')">
<input type="hidden" name="someName" value="helloworld" />
<a href="mailto:mail#example.org" target="_blank" onclick="return submit();">
Submit
</a>
</form>
#Wael: Thanks. The second solution is equivalent to this.
<form id="myForm2" action="test.php" method="post">
<input type="hidden" name="someName" value="helloworld" />
Submit 2
</form>
The missing target attribute was the issue.
In Firefox it works as required. In Chrome it leads to
1. Opens the mail client
2. Posts to test.php
3. Opens a new browser tab with url mailto:mail#example.org (and focus)
With your first solution it is the same. How to avoid 3.?

How to submit form data with Zurb Foundation

I'm a beginner trying to set up my first form with Zurb Foundation, and I'm not able to find in the documentation the info on how to actually pass the data. It's just a basic contact form with name/email/message that I'd like sent to my email once people click the Submit button... and I don't know how to do that.
I apologize for the simple question, your help is greatly appreciated.
Zurb foundation is front end frame work for website design and development , if you want to submit the form or do server communications, please read some basics,
HTML form and input : http://www.w3schools.com/html/html_forms.asp
Submitting HTML form using Jquery AJAX :
Submitting HTML form using Jquery AJAX
AJAX - Send a Request To a Server : http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp
The HTML part:
<form action="form_contact_process.php" method="POST" name="contact" id="contact">
<fieldset>
<legend>Contact form</legend>
<div class="row collapse">
<label for="name">Name</label>
<input type="text" name="name" id="name">
</div>
<div class="row collapse">
<label for="email">Email</label>
<input type="text" name="email" id="email">
</div>
<div class="row collapse">
<label for="phone">Phone</label>
<input type="text" name="phone" id="phone">
</div>
<div class="row collapse">
<label for="message">Message</label>
<textarea name="message" id="message" rows="5"></textarea>
</div>
<div class="row collapse">
<input class="button small large-12" type="submit" value="Submit">
</div>
</fieldset>
</form>
Then over at form_contact_process.php:
<?php
$name = $_POST['name'];
...
echo $name;

Submit form to another page within the same domain

How to submit form to another page within the same domain which has no form ID or name?
Form that needs to submit to another page:
<form id="login_form" action="roundcube" method="post">
<div class="input-req-login">
<label for="user">Email Address</label>
</div>
<div class="input-field-login icon username-container">
<input name="_user"
id="rcmloginuser"
autofocus="autofocus"
placeholder="Enter your email address."
class="std_textbox"
type="text"
tabindex="1" required>
</div>
<div style="margin-top:30px;" class="input-req-login">
<label for="pass">Parola</label>
</div>
<div class="input-field-login icon password-container">
<input name="_pass"
id="rcmloginpwd"
placeholder="Enter your email password."
class="std_textbox"
type="password"
tabindex="2" required>
</div>
<div class="controls">
<div class="login-btn">
<button type="submit"
onclick="document.getElementByName("form").submit()"
tabindex="3">Autentificare</button>
</div>
Target form:
<form name="form" action="./" method="post">
<input type="hidden" name="_token" value="543e98f5e6cc25841fc0df79cb939590">
<input type="hidden" name="_task" value="login">
<input type="hidden" name="_action" value="login">
<input type="hidden" name="_timezone" id="rcmlogintz" value="_default_">
<input type="hidden" name="_url" id="rcmloginurl" value="">
<table>
<tbody>
<tr>
<td class="title">
<label for="rcmloginuser">Utilizator</label>
</td>
<td class="input">
<input name="_user"
id="rcmloginuser"
size="40"
autocapitalize="off"
autocomplete="off"
type="text">
</td>
</tr>
<tr>
<td class="title">
<label for="rcmloginpwd">Parolă</label>
</td>
<td class="input">
<input name="_pass"
id="rcmloginpwd"
size="40"
autocapitalize="off"
autocomplete="off"
type="password">
</td>
</tr>
</tbody>
</table>
<p class="formbuttons">
<input type="submit"
class="button mainaction"
value="Autentificare" />
</p>
</form>
Ok, I have taken a look at your sites now. This is actually quite simple.
I guess what you are trying to do is to set up a personalized web site to log in so you can give your own look and feel. And roundcube, I guess that is a standard mail system you have installed?
Well the problem is that roundcube not only sends user name and password. If you look at the HTML code you also see:
<input type="hidden" name="_token" value="5b6a757df5eee91fa7ee7171466b8b2a">
<input type="hidden" name="_task" value="login">
<input type="hidden" name="_action" value="login">
<input type="hidden" name="_timezone" id="rcmlogintz" value="_default_">
<input type="hidden" name="_url" id="rcmloginurl" value="">
All these are hidden values that are automatically sent with the log in POST. You probably need to add the last 4 of them.
There might be a big problem for you though. The first one called _token I have a theory that this is a randomized string that the server will require you to provide. I can be wrong but if I am correct you will not be able to do what you want. The reason for having this random string is to prevent users from posting log ins from other forms (that is if I am correct)
Maybe it is possible for you to turn off this randomized string in the roundcube admin settings? If not I think you don't have an easy way to proceed unless you want to dig into the code of round cube.
Edit: I just tried submitting the original form without the _token and it does not work. so unfortunately you are out of luck this time.
I am not quite sure I understand your question, but I guess you are writing a new page and want to post to another page. What if you do like this?
<form id="login_form" action="http://webmail.mysite.com/roundcube/" method="post">

SEO Url not changing upon form submission

Am using SEO URls to load my pages ie http://www.mywebsite.com/p/page1/100 but am having a problem with my search form. When I click submit, instead of the entire url changing to the stated one in the form, it just appends the variables to the url eg http://www.mywebsite.com/p/page1/100?p=search&q=Any+Query+String+here.
My question is, how do I replace the entire URL with the form variable instead?
Here is my form code:
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
OK I solved it using a hack I think???
Apparently if I append a variable to the action url, this will force the browser to load the new url instead of append the form variable to the existing url.
Eg.
<form action="<?php $_SERVER['PHP_SELF'] ?>?p=search" method="get">
<input type="text" onfocus="if(this.value==this.defaultValue) this.value='';" onblur="if(this.value=='') this.value=this.defaultValue;" name="q" value="Search" />
<input type="hidden" value="search" name="p" />
<input type="submit" value="Search" class="submit" />
</form>
This worked for me but I dunno if it's the right way to achieve this or it's a hack.

Zend Controller fails to retrieve POST values from Zend Form in Chrome and Safari

EDIT: Resolved itself. Recreated the LoginController and issue is gone. Thanks for the responses!
So I'm fairly new to Zend, so maybe I'm missing something blaringly simple. The scenario is pretty straightforward. I have a Zend_Form on index submit to /login, where I want to handle the username and password vars. I use a custom decorator to setup the form, and the resulting HTML looks like so:
<form id="loginForm" name="loginForm" enctype="application/x-www-form-urlencoded" method="post" action="/login">
<div class="input-container" id="username-container">
<input type="text" name="username" id="username" value="" helper="formText">
<div class="input-overlay">Username/Email</div>
</div>
<div class="input-container" id="password-container">
<input type="password" name="password" id="password" value="" helper="formPassword">
<div class="input-overlay">Password</div>
</div>
<div id="dropdown-checkbox-forgot-container">
<div class="checkbox-container" id="checkbox-container-rememberMe">
<input type="hidden" name="rememberMe" value="0">
<input type="checkbox" name="rememberMe" id="rememberMe" value="1" checked="checked" helper="formCheckbox" text="Remember me" class="light">
<div class="light checkbox-text" id="checkbox-text-rememberMe">Remember me</div>
</div>
Forgot password?
</div>
<input type="image" name="login" id="dropdown-login-submit" src="">
</form>
Great! Let's submit it! I put a simple var_dump in my LoginController to confirm that the values are transferred properly. var_dump($this->getRequest()->getPost()). FF and IE both show the values as they are supposed to be. However, Chrome and Safari do not show the username or password inputs. There is only a rememberMe value in the POST array. Strange...
Now I figure it might be Zend's accessing of the POST superglobal, so I change my code to var_dump($_POST). Same problem. In frustration I tried var_dumping both the $_POST and $this->getRequest()->getPost()....and it worked!? It dumped one copy with only the rememberMe input and one copy with everything (username and password included). No idea why or how that worked. Any insight as to what the problem might be would be greatly appreciated!
Recreated my LoginController through ZendTool and all worked as expected.