Here is my form.
<form method="post" name="frm">
<label>Name*<input type="text" name="Name" value="<?php echo $r['Name'] ?>" onblur="if(this.value.length<3) alert('Name too short');" /></label>
<label>Username*<input type="text" name="UN" value="<?php echo $r['UN'] ?>" onblur="if(this.value.length<5) alert('Username too short');" /></label>
<label>Password*<input type="password" name="PW" onblur="validation()" /></label>
<label>Confirm Password*<input type="password" name="CM" onblur="validation()" /></label>
<?php } ?>
<input type="submit" name="Submit" value="<?php if($new) echo 'Register'; else echo 'Update'; ?>" />
</form>
Without writing separate onBlur events I am trying to get all these events into a function called validation() as I have done for password and confirm-password fields. Here is my validation function:
<script language="javascript">
function validation() {
var password = document.frm.PW.value;
var password2 = document.frm.CM.value;
if (password.length < 5) {
alert ("Password too short");
}
else if (password != password2) {
alert("password mismatch");
}
}
</script>
But with this code once I have filled password, and when I am about to start inputting for confirm-password field, it alerts the message "password mismatch". How to get rid of this? And for all the form tags if I am validating and using validation() function, then in each tag do I have to call onblur=validation()?
Don't have the password validation fired on the main password change - have it fired when you alter password2 or when you click submit. :)
If you insist on checking when you update password AND password 2, I would just add a check to see if password2 had been left blank:
else if(password !== password2 && password2 !== ""){
But doing ALL your checks on submit is a much cleaner solution (and as Rake says, it would be neater still to have a span that is updated instead of an alert).
Related
Hi I am trying to somehow create a custom payment gateway. The one I am using is integrated in Gravity Forms and I have created a new php gateway MeprTransactiumGateway.php to include this new custom gateway.
I am able to capture the payment but not assign the subscription to the member. The member is being registered in memberpress but with no Memberships.
This is the code I am editing:
public function display_payment_form($amount, $user, $product_id, $txn_id) {
$mepr_options = MeprOptions::fetch();
$prd = new MeprProduct($product_id);
$coupon = false;
$txn = new MeprTransaction($txn_id);
//Artifically set the price of the $prd in case a coupon was used
if($prd->price != $amount) {
$coupon = true;
$prd->price = $amount;
}
ob_start();
$invoice = MeprTransactionsHelper::get_invoice($txn);
//echo $invoice;
$email = MeprTransactionsHelper::get_email($txn);
echo do_shortcode("[gravityform id=\"4\" field_values=\"email=".$email."\" title=\"Subscription\" description=\"false\" ajax=\"true\"]");
/* ?>
<div class="mp_wrapper mp_payment_form_wrapper">
<form action="" method="post" id="payment-form" class="mepr-form" novalidate>
<input type="hidden" name="mepr_process_payment_form" value="Y" />
<input type="hidden" name="mepr_transaction_id" value="<?php echo $txn_id; ?>" />
<div class="mepr_spacer"> </div>
<input type="submit" class="mepr-submit" value="<?php _e('Submit', 'memberpress'); ?>" />
<img src="<?php echo admin_url('images/loading.gif'); ?>" alt="<?php _e('Loading...', 'memberpress'); ?>" style="display: none;" class="mepr-loading-gif" />
<?php MeprView::render('/shared/has_errors', get_defined_vars()); ?>
<noscript><p class="mepr_nojs"><?php _e('Javascript is disabled in your browser. You will not be able to complete your purchase until you either enable JavaScript in your browser, or switch to a browser that supports it.', 'memberpress'); ?></p></noscript>
</form>
</div>
<?php*/
}
The gravity form is being echoed using do_shortcode. The payment is going through. Then a success or fail message is displayed as confirmation. I would like that if a success message is received the membership is actually submitted (this was previously done in the html form code that is commented out)
Controller : User.php
public function index()
{
log_message('debug', ' Index User');
die("should never get here");
}
public function login()
{
log_message('debug', ' Login Entered');
echo '<pre> Printing Login data:';
print_r($_POST);
echo "</pre>";
$data['pageHeader'] = "Login";
$data['message'] = 'temporary message - This will be the login stuff';
$this->session->set_flashdata('flashInfo', 'Login form will go here');
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'required');
if ($this->form_validation->run() === FALSE)
{
log_message('debug', ' validation run FALSE');
$this->load->helper('form');
$this->render_page('user/login', 'public_header', 'footer', $data);
}
else
{
log_message('debug', ' validation run TRUE');
$remember = (bool) $this->input->post('remember');
if ($this->ion_auth->login($this->input->post('username'), $this->input->post('password'), $remember))
{
log_message('debug', ' redirect Dashboard');
redirect('dashboard');
}
else
{
$_SESSION['auth_message'] = $this->ion_auth->errors();
$this->session->mark_as_flash('auth_message');
log_message('debug', ' redirect user login');
redirect('user/login');
}
}
}
Known from log:
function login entered,
$_POST always 'empty',
form validation-> always FALSE thus debug message is logged and form redisplayed
Form user/login.php
<?php defined('BASEPATH') OR exit('No direct script access allowed');?>
<div class="container">
<?php echo $message;?>
<h1>Login</h1>
<form action="#" method="post">
<div class="imgcontainer">
<img src="http://www.hdkumdo.com/smen/assets/crow2.png" alt="Swordsmen Martial Arts">
</div>
<div class="container">
<label for="username"><b>Username</b></label>
<input type="text" placeholder="Enter Username" name="username" id="username" required autofocus>
<label for="password"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="password" id="password" required>
<button type="submit" name="login" id="login" value"login" >Login</button>
<label>
<input type="checkbox" checked="checked" name="remember" id="remember"> Remember me
</label>
</div>
<div class="container" style="background-color:#f1f1f1">
<button type="button" class="cancelbtn">Cancel</button>
<span class="psw">Forgot password?</span>
</div>
</form>
</div>
Copied an example from https://www.codeigniter.com/user_guide/libraries/form_validation.html
and form posts data but if I change function index to login it does not work.
Menu link : Login works fine.
Everything seems to be connected...login form displays, Controller function login is entered but it seems like there is no POST data so the form is simply redisplayed. I have 2 simple validation rules so it seems that validation->run should return true if I just enter any data into the fields.
I am sure it's something simple but for the life of me I can't see what.
First of all make sure you have loaded form validation library
$this->load->library('form_validation');
//set field validation
$this->form_validation->set_rules('fieldname','Field Name','required');
if($this->form_validation->run())
{
//then process form
//redirect
}
else {
//load view
}
I'm creating a Shopify website, and I'm currently working on the customer registration form. I need to make a Confirm Password field. Does anybody know how to do this in Shopify?
Just Got it working on my register page:
The two password fields:
<div id="create_password_container">
<label for="password">Your Password<em>*</em></label>
<input type="password" value="" name="customer[password]" id="create_password" {% if form.errors contains "password" %} class="error"{% endif %}>
</div>
<div id="password_confirm_container">
<label for="password_confirmation">Password Confirmation</label> <span class="password-match">PASSWORDS DO NOT MATCH</span>
<input type="password" value="" name="customer[password_confirmation]" id="password_confirm" />
</div>
Javascript:
$('form#create_customer').submit(function(e) {
if ( $('#create_password').val() === $('#password_confirm').val()) {
//alert('Password Good!!');
} else {
$('.password-match').fadeIn("slow");
e.preventDefault(); // stops our form from submitting
}
});
The CSS for the password not-matching message:
.password-match {font-size: 12px; color: #f1152f; display:none;}
When customers receive the link to their activation they are prompted for both a password and a password confirmation. Failing that - you can add an extra input (password confirmation) and then do a simple comparison with javascript. Something like:
.... <label for="password" class="login">{{ 'customer.register.password' | t }}</label>
<input type="password" value="" name="customer[password]" id="password" class="large password" size="30" />
<label for="password-confirm" class="login">{{ 'customer.register.password' | t }}</label>
<input type="password" value="" name="customer[password-confirm]" id="password-confirm" class="large password" size="30" /> ....
and then with jquery - something like
$('form').submit(function(e) {
e.preventDefault(); // stops our form from submitting
if ( $('#password').val() === $('#password-confirm').val()) {
$('form').submit();
}
});
That was done off the top of my head - so not tested. It should compare the two password strings - and if they match, allow the form to submit. Of course - you'll probably want to do stuff like show a pop up... alert or message to say your passwords don't match etc. In which case:
$('form').submit(function(e) {
e.preventDefault(); // stops our form from submitting
if ( $('#password').val() === $('#password-confirm').val()) {
$('form').submit();
} else {
// put your validation message in here - this could be showing an element... or showing an alert etc
alert("Your passwords don't match dummy!")
}
});
You could just as easily do
$( ".errorMessage" ).fadeIn( "slow", function() {
// Animation complete
$(this).hide();
});
instead of the alert - but you'd need to make sure you have a div with a class of .errorMessage that contains your error message :)
I want a help in my Contact form. I want that when a user inputs his email id in input field & if it is wrong i.e without # the input box should shake (which depicts an error) & when user enters correct email Id, it should accept it.
The problem in my current code is, when user enters correct email Id, even then the input field shakes. Need to validate the input field for correct Email.
Any help would be appreciated.
Thanks in advance.
<form id="form_id" method="post" action="<?php $_SERVER['PHP_SELF'] ?>" onsubmit="javascript:return validate('form_id','email');" novalidate>
<input type="text" id="email" name="email" value="<?php if (isset($_POST["email"])) {echo $ema;} ?>" class="error"/>
<br><br>
<button type="submit" name="submit" class="getaccess-btn">Get Access </button>
</form>
The js for the same is:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript">
function validate(form_id,email) {
var reg = /^([A-Za-z0-9_\-\.])+\#([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {
$(document).ready(function(){
$("button").click(function(){
$("#email").delay(0).animate({"left": "-=30px"}, 80).animate({"left": "+=60px"}, 80).animate({"left": "-=60px"}, 80).animate({"left": "+=60px"}, 80).animate({"left": "-=30px"}, 80);
});
});
return false;
}}
</script>
this php code
<?php
$your_email = "youremailid#gmail.com"; // email address to which the form data will be sent
$subject = "Contact Message"; // subject of the email that is sent
$thanks_page = "thank-you.html"; // path to the thank you page following successful form submission
// Nothing needs to be modified below this line
if (isset($_POST["submit"])) {
$ema = trim($_POST["email"]);
if (get_magic_quotes_gpc()) {
$ema = stripslashes($ema);
}
$error_msg=array();
if (empty($ema) || !filter_var($ema, FILTER_VALIDATE_EMAIL)) {
$error_msg[] = "Your email must have a valid format, such as name#mailhost.com";
}
$email_body =
"Email of sender: $ema\n\n" .
"$com" ;
// Assuming there's no error, send the email and redirect to Thank You page
if (!$error_msg) {
mail ($your_email, $subject, $email_body, "From: $nam <$ema>" . "\r\n" . "Reply-To:");
header ("Location: $thanks_page");
exit();
}
}
?>
The css for the same is:
.error{height:auto;width:100px;position:absolute;}
I can't understand your issue properly, but if you are working with email validation then there is no need of javascript. You can simply use email as input type in HTML5:
for ex, you can write as following:
<form>
<input type="email" name="email" required>
<input type="submit">
</form>
this will automatically validate input field for # and ..
fiddle is here
I am trying to send this form, but this does not work
The processor in jquery :
function processorform(id)
{
jQuery(function()
{
var $ = jQuery;
$('.sp-poll-'+id+' form').submit(formProcess);
function formProcess(e) {
e.preventDefault();
var poll = $('input[name=poll]').val(),
answer = $('input[name=answer]:checked').val(),
div = $(this).parent(),
action = $(this).attr('action');
}
}
The HTML code
<div class="sp-poll-1">
<form method="post" action="include/submit.php" class="format" onsubmit="processorform('1');">
<input type="hidden" name="poll" value="<?php echo $pollid; ?>"/>
<input type="hidden" name="backurl" value="<?php echo $thisPage; ?>"/>
<input type="radio" name="answer" value="<?php echo $key; ?>" id="poll-<?php echo $pollid; ?>-<?php echo $key; ?>" class="sp-input-radio" />
<input type="submit" class="sp-btn" value="<?php _e('Send'); ?>"/></p>
</form>
</div>
When I try to send the form, it never works and always goes to submit.php and doesn't show the div results. I don´t know what´s wrong with the code or what the fix might be.
Thank´s for the help.
If you change this line:
onsubmit="processorform('1');"
to this:
onsubmit="processorform('1');return false;"
You won't go to submit.php.
But since you're using AJAX to post your request, some other errors may appear, since we don't have all the varibles to check if it will work.