Ajax submit multiple forms using a single forms' values - php

So lets say I have some forms like this:
Form A:
<form name="formA">
<input type="text" name="username">
<input type="text" name="password">
</form>
Form B:
<div style="display:none;">
<form name="formB">
<input type="text" name="username">
<input type="text" name="password">
</form>
</div>
Form C:
<div style="display:none;">
<form name="formC">
<input type="text" name="username">
<input type="text" name="password">
</form>
</div>
Forms B and C are hidden, I have them there because after a user enters their username and password in form A, I need to also use that username and password information they submitted to be used in forms B and C, and then submit all forms at once. This is so I can submit a login to multiple parts of my website using just 1 login form. How exactly should I go about doing this?
-Thanks!

If you don't need https for login function, you can try this using jQuery and ajaxForm plugin:
<form name="formA" action="actionA">
<input id="usernameA" type="text" name="username">
<input id="passwordA" type="password" name="password">
</form>
<div style="display:none;">
<form name="formB" action="actionB">
<input id="usernameB" type="text" name="username">
<input id="passwordB" type="password" name="password">
</form>
</div>
<div style="display:none;">
<form name="formC" action="actionC">
<input id="usernameC" type="text" name="username">
<input id="passwordC" type="password" name="password">
</form>
</div>
$('#formA').submit(function() {
var username = $('#usernameA').val();
var password = $('#passwordA').val();
$('#usernameB').val(username);
$('#passwordB').val(password);
$('#usernameC').val(username);
$('#passwordC').val(password);
$('#formB').ajaxForm(function() {
alert("You have been logged in at B");
});
$('#formC').ajaxForm(function() {
alert("You have been logged in at C");
});
});
When you send an ajax request to the server for login at B and C, if your server send back a cookie on successful login, I think you're good to go :P

You can use multiple values for each variable name. For example:
<form name="formABC">
<div id="formA">
<input type="text" name="username[]">
<input type="text" name="password[]">
</div>
<div id="formB" style="display:none;">
<input type="text" name="username[]">
<input type="text" name="password[]">
</div>
<div id="formC" style="display:none;">
<input type="text" name="username[]">
<input type="text" name="password[]">
</div>
</form>

1) You should be using type="password" for password input fields.
2) You cannot submit more than one form at a time. Only the data from the form that is being submitted will be sent. From what I understand that you're trying to do, you want one button to open three different pages to three different login forms to store three different sessions. There are better ways to make your sessions (or cookies) work across multiple sections of your website, such as attaching the session ID to the URL so you always have it for every page load.
3) A form needs to have an action defined.

Related

Html form tag autocomplete="off" attribute not working on chrome browser

I have user registration form. Form contains username and password field.
At the time of user registration username and password fields automatically populated values.
I have used form "autocomplete" attribute, but not working on chrome browser.
This is my code,
<form method="post" action="" autocomplete="off">
<input type="text" id="first_name" name="first_name">
<input type="text" id="last_name" name="last_name">
<input type="text" id="username_name" name="username_name">
<input type="text" id="password" name="password">
In my experience, Chrome only autocompletes the first <input type="password"> and the previous . So I added:
<input style="display:none">
<input type="password" style="display:none">
To the top of the <form> and the case was resolved.

Form information not being 'seen' by MySQL

I've made a new log in / register template which uses CSS3 and HTML, yet I had a working form, but very basic, before this. So I decided to make another 'form' which should look like this:
http://www.script-tutorials.com/css 3-modal-popups/
Now, I use this form to handle my registration:
<!-- Popup Form #2 -->
<div class="popup">
<h2>Sign Up</h2>
<p>
Please enter your details here.
</p>
<div>
<form action="register.php" action="post">
<label for="username">Username</label>
<input type="text" id="username" placeholder="Max 32 characters" name="username" />
</div>
<div>
<label for="password">Password</label>
<input type="password" id="password" placeholder="Password" name="password" />
</div>
<div>
<label for="lastname">Lastname</label>
<input type="text" id="lastname" placeholder="Lastname" name="lastname" />
</div>
<div>
<label for="email">E-mail</label>
<input type="email" id="email" placeholder="example#hotmail.com" name="email" />
</div>
<input type="submit" value="Join the Community" /> or
</form>
Yet when I test this form, it will say the data is stored (My register.php file comes with a if-statement), yet it displays nothing. (No username, (password still gets hashed / stored, though I'm not sure if it's really handling it), last name and e-mail.
I've checked and double checked the 'name' attributes' value in the register.php file. And those are correct.
Pretty sure you are accessing your form values using $_POST. The problem is that in your form tag you are setting action twice, one of which is correct i.e. action="register.php" and the other action="post" is incorrect.
Try:
<form action="register.php" method="post">
and remember to enclose variables in quotes, for example
$foo = $_POST['foo'];
$bar = $_POST['bar'];
$sql_query = "INSERT INTO my_table (foo, bar) VALUES ('$foo', '$bar');";

I want the form action to be decided based on whether a check box has been selected or not using php

If the check box below is selected I want the form to be processed by teacherprocess.php and if the checkbox is not selected I want the form to be processed by process.php. I'd rather this be done using PHP as I know some people do not support javascript in their browsers.
<form class="form-horizontal" action="#" method="post" name="form">
<div class="control-group">
<input class="input-block-level" type="text" id="username" name="username" placeholder="Username">
</div>
<div class="control-group">
<input class="input-block-level" type="password" name="password" id="inputPassword" placeholder="Password">
</div>
<input type="checkbox" name="teacher" value="I am a teacher">
<input type="submit" name="submit2" value="Student" class="btn btn-info">
</form>
Send the form to an intermediate PHP page:
<form class="form-horizontal" action="selector.php" method="post" name="form">
Then decide, based upon the checkbox being checked, which page to execute:
<?php
// selector.php
if (isset($_POST['teacher'])) {
require ('teacherprocess.php');
} else {
require ('process.php');
}
Disclaimer: I didn't try that.
if you want php to do this. Here it goes
<form class="form-horizontal" action=" teacherprocess.php" method="post" name="form">
in teacherprocess.php check
if(!isset($_POST['teacher']))
header('Location: process.php');

wordpress login issue

i have created a custom popup login box. and use form settings like that
<form action="<?php bloginfo('url'); ?>/wp-login.php?redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']); ?>" method="post" autocomplete="off">
and i use input feilds like that
<input id="login_username" name="user_name" type="text" value="" class="pop-input surfix" /><span id="placeholder_user_login">Username</span>
<input id="login_password" name="user_password" type="password" value="" class="pop-input" /><span id="placeholder_user_pass">Password</span>
<input id="register" type="submit" value="Login" class="popup-login-btn" />
but it redirecting to wp-login.php except it should process the login and redirect to the pages where from user started login.
please guide me how can i fix this.
thank you all
actually the issue was with the name element of the input field.
When i check the wp-login.php page i discover the wordpress changes the name of input fields.
<input id="login_username" name="user_name"
<input id="login_password" name="user_password"
to
<input id="login_username" name="log"
<input id="login_password" name="pass"
So i just simply replace the names and all issues were sorted out.
Thank you all

Inserting facebook user info into a form

Basically what i want to do is when the user allows an application he will automatically signup for my autoresponder list, so i need to pass the user name and email to the form and automatically submit the form.
Here is the first part when i get the user info:
window.fbAsyncInit = function() {
FB.init({appId: 'xxxxxxxxxxxxxxx', status: true, cookie: true, xfbml: true});
};
FB.Event.subscribe('auth.login', function(response) {
if (response.session) {
FB.api({
method: "fql.query",
query: "SELECT name,email FROM user WHERE uid = " + response.session.uid
}
here is the form:
<form method="post" class="af-form-wrapper" action="http://www.aweber.com/scripts/addlead.pl" >
<div style="display: none;">
<input type="hidden" name="meta_web_form_id" value="XXXXXXXX" />
<input type="hidden" name="meta_split_id" value="" />
<input type="hidden" name="listname" value="XXXXXX" />
<input type="hidden" name="redirect" value="http://www.aweber.com/thankyou.htm?m=default" id="redirect_e96b2b57089ff7b9fbdbc6ac41355eed" />
<input type="hidden" name="meta_adtracking" value="XXXX" />
<input type="hidden" name="meta_message" value="1" />
<input type="hidden" name="meta_required" value="name,email" />
<input type="hidden" name="meta_tooltip" value="" />
</div>
<div id="af-form-XXXXXXXX" class="af-form"><div id="af-header-XXXXXXXX" class="af-header"><div class="bodyText"><p> </p></div></div>
<div id="af-body-XXXXXXXX" class="af-body af-standards">
<div class="af-element">
<label class="previewLabel" for="awf_field-22176678">Name: </label>
<div class="af-textWrap">
<input id="awf_field-22176678" type="text" name="name" class="text" value="" tabindex="500" />
</div>
<div class="af-clear"></div></div>
<div class="af-element">
<label class="previewLabel" for="awf_field-22176679">Email: </label>
<div class="af-textWrap"><input class="text" id="awf_field-22176679" type="text" name="email" value="" tabindex="501" />
</div><div class="af-clear"></div>
</div>
<div class="af-element buttonContainer">
<input name="submit" class="submit" type="submit" value="Submit" tabindex="502" />
<div class="af-clear"></div>
</div>
</div>
</div>
<div style="display: none;"><img src="http://forms.aweber.com/form/displays.htm?id=HGwsjMxsLOwM" alt="" /></div>
</form>
Now i don't really need all the form code because i don't even want it to show (invisible) and all the forms basically have the same inputs names (name="name", name="email")
so i just wanna enter the list name and pass the user's name and his email to the fields and auto submit it using PHP/JavaScript/Jquery.
There is already scripts which does that and i want to build one my self ;)
EDIT: My friend just gave me this code:
customar_formcode=customar_formcode.replace("{email}", user.email);
customar_formcode=customar_formcode.replace("{name}", user.name);
document.getElementById(\'inneraction\').innerHTML=customar_formcode;
document.getElementById(\'form_id\').submit();
he said the user.name and use.email need to be set from the fql first, honestly i don't understand what i need to do next, do i need to insert the code on the page anyway? do i need to post the form in some special javascript format? what does 'inneraction' means?
Thanks!
Instead of applying this type of patch you may use FB registration........
for detailed information on FB registration see below link
http://developers.facebook.com/docs/plugins/registration/

Categories