I have the next HTML form:
<form name="register" method="post" action="register.php" >
<fieldset>
<legend>Register</legend>
<input type="hidden" name="regform" value="true" />
<label for="username">Username:</label>
<input type="text" name="username" id="username" />
<br />
<label for="email">Email:</label>
<input type="text" name="email" id="email" />
<br />
<label for="password1">Password:</label>
<input type="password" name="password1" id="password1" />
<br />
<label for="password2">Password:</label>
<input type="password" name="password2" id="password2" />
<br />
<?php
$config = new Config();
$publickey = $config->getCaptchaPublicKey();
echo recaptcha_get_html($publickey);
?>
</fieldset>
<input type="submit" value="Register!" />
What I'd like to do, is that when the user presses the submit button, i send the data from the forms via AJAX and verify them.
But I was wondering how I update the recaptcha? I can verify it in my PHP script, and echo a new one included with the error. But how do I send this
back to the client and let javascript (jQuery) replace the old reCAPTCHA with the new?
Hope someone can help me with this.
Greets,
Luxo
PS: Should I use a javascript encryption to encrypt the passwords before sending to the server?
1) to request the image you must request the recaptcha with the correct headers in AJAX
that is send the headers for requesting an image in your case
2) if validating through AJAX you must encrypt or otherwise any bum can touch the passwords
for that just encrypt with the same encryption you would use to store in your database
ex: if you encrypt with md5 from php
instead encrypt the pwd with md5 using JS and send the hash
If you use jQuery then $('#form-id').serialize(); is what you're looking for. Use the data returned from this function as data to post an Ajax.
If you don't have HTTPS then it is worthless to encrypt password with JavaScript.
Related
I have a simple html form and want to set a cookie value to 1, for example, if the submit button was pressed. How can I do it?
The form looks like that:
<form action="auth.php">
<label for="fname">Enter your name: </label>
<input type="text" id="fname" placeholder="John" required />
<br />
<br />
<label for="fsurname">Enter your surname:</label>
<input type="text" id="fsurname" placeholder="Doe" required />
<br />
<br />
<label for="email">Enter your email:</label>
<input type="email" id="email" name="email" placeholder="stupidlady123#yandex.ru" required>
<br />
<br />
<input type="submit" value="Register!" />
<!-- <?php
setcookie('Form', '1');
echo $_COOKIE['Form'];
?> -->
</form>
I've tried setting cookie in an action file (auth.php) and after submit button. But, as I understand, once data is sent to the server, I cant set the cookie any longer.
First of all, you need to put your setcookie before any html tag as you can see in php doc : https://www.php.net/manual/fr/function.setcookie.php ;
Secondly, your cookies can't be used because you're not setting him for every documents. You have to place '/' in your setcookie like :
<?php setcookie('form','1',time()+60*60*24*30,'/'); ?>
You can use instead $_SESSION which is more modulable.
I have created one app in facebook (using facebook canvas). It is working properly, but I want to know, how can I put a registration form with some fields???
I have written the code for form,
<form action="../form/fbform.php" method="post">
My Name
<input maxlength="50" name="name" type="text" value="" />
My Email
<input maxlength="50" name="email" type="text" value="" />
I Work for
<input maxlength="50" name="cmpny" type="text" value="" />
My Friend
<input maxlength="50" name="frdname" type="text" value="" />
My Friend's Email
<input maxlength="50" name="frdemail" type="text" value="" />
<input name="try" type="submit" value="Submit" />
</form>
That is the code for my form, but after submission it showing blank page.
In action I have written fbform.php, In that file, I have the written the sql code to insert these form details into my website database. and also I have written redirect url to my app. but it's not working.
How can put the registration form in my app and how can I get those details (what users filled in those fields) in my website database or some excel sheet??
I think you need to see the fbml tags to post your data to your desired web page and try the GET method and use the session object of the facebook to retrieve your details .
<form action="../form/fbform.php" method="POST">
<input type="text" name="test1"></input>
<input type="hidden" name="fb_sig_session_key" value=”<?php $_GET[‘fb_sig_session_key’]”></input>
<input type="hidden" name="user_id" value=”<?php $_GET[‘user_id’]”></input>
<input type="submit" name="Submit"/>
</form>
I wish to use a single HTML form to send the user's input to my email, and simultaneously a web page that the user views their input. At present I can only get one of the two options; the web page re-direct which displays the users input.
Is there a back-side PHP script to accomplish sending the user input to both an email and a web page?
Form code:
<form id="form1" name="form1" method="post" action="TEST.php">
<input name="name" type="text" class="formdetail" id="name" />
<input name="color" type="text" class="formdetail" id="color" size="45"/>
<input name="animal" type="text" class="formdetail" id="animal" size="45"/>
<input name="room" type="text" class="formdetail" id="room" size="45"/>
<input name="water" type="text" class="formdetail" id="water" size="45"/>
<input name="email2" type="text" class="formdetail" id="email" size="45"/>
<input type="submit" name="submit2" id="submit" value="Submit" />
<input type="hidden" name="recipients" value="http://www.Website.net/TEST.php" />
<input type="hidden" name="good_url" value="http://www.Website.net/TEST.php" />
</form>
Results web page page code:
<p>Your results, <?php echo htmlspecialchars($_POST['name']); ?>:</p>
<p>1. Your favorite color reveals: <?php echo htmlspecialchars($_POST['color']); ?>.</p>
<p>2. Your favorite animal reveals: <?php echo htmlspecialchars($_POST['animal']); ?>.</p>
<p>3. This reveals: <?php echo htmlspecialchars($_POST['room']); ?>.</p>
<p>4. This reveals: <?php echo htmlspecialchars($_POST['water']); ?>.</p>
So if I'm understanding your question correctly you want that script to send the user on to the next page after it emails you?
It's really very simple :)
First, you need to store your data into some persistent store, such as a session using start_session() on your first page. This will allow you to store data in the $_SESSION super global. Then on your next page after using:
http_redirect($newUrl);
You can grab the session data using that same superglobal
Place that after your email code and you should be good to go. If you're asking something a little different please don't hesitate to call me out and we can figure this thing out.
For reference: http_redirect() in a nutshell
And: php sessions in a nutshell
Ok i am trying to find if this is possible, i have a single page that has two login forms. But uses the same username and password. Is it possible whereas once i log into one form my username is pulled from the from that already has my username and the password is pulled from the database?
<form action="home.php" method="post" id="LoginForm" style="color:#FFF">
<input type="hidden" name="SessionID" value="new"></input>
Username:
<input type="text" name="AccountNo" value="" class="input" size="28"></input>
<BR /><BR />
Password:
<input type="password" name="Password" value="" class="input" size="30"></input>
<BR />
<input type="image" src="images/input-img.gif" value="Log On" class="input-img"></input>
<BR /><br />
Register now! Forgotten your password?
</form>
If your question is whether it is possible, then answer is yes it is possible.
After you submit the form, you can use JavaScript to read the username from first form and populate it in the second form. To get password, you can AJAX.
i start with form tag the add name age phonenumber resume input boxes and a captcha but not able to send the form by ajax to a php file which will mail. when i send the mail the screen refreshes**
<form action="#" name="MYFORM" id="MYFORM">
<label>Name</label>
**then i put other labels**
<input name="name" size="30" type="text" id="name">
<br clear="all" />
<label>Email</label>
<input name="email" size="30" type="text" id="email">
<br clear="all" />
<div id="wrap" align="center">
<img src="get_captcha.php" alt="" id="captcha" />
<br clear="all" />
<input name="code" type="text" id="code">
</div>
<img src="refresh.jpg" width="25" alt="" id="refresh" />
<label> </label>
<input value="Send" type="submit" id="Send">
</form>
you can use SESSION in the file get_captcha.php to store the value of the captcha code and when you submit the code the match the post value of the captcha code entered by the user to the value saved in the SESSION .
Assuming you are looking for ajax form submit
$.ajax({
type:'POST',
url: 'yourphpfile.php',
data:$('#formid').serialize(),
success: function(response)
{
// do what ever you want with the repose
}
});
in your php file you specify the validation for the captcha by comparing the captcha value generated and stored in the session . if the captcha fails display the error using javascript based on the response you get