form 2 button + javascript issue - php

<form action="index.php?page=checkin" method="post" name="regForm">
<div id="First_1">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="5">
<tr>
<td style="padding: 5px;">
Fullständiga namn:
</td>
<td>
<input name="full_name" type="text" id="full_name" class="required">
</td>
</tr>
<tr>
<td style="padding: 5px;">
Email:
</td>
<td>
<input name="usr_email" type="text" id="usr_email3" class="required">
</td>
</tr>
<tr>
<td style="padding: 5px;">
Sex:
</td>
<td>
<select name="sex">
<option value="male">
Kille
</option>
<option value="female">
Tjej
</option>
</select>
</td>
</tr>
<td>
<input type="submit" id="continue" value="Fortsätt">
</td>
</table>
</td>
</tr>
</table>
</div>
<div id="Next_2" style="display: none">
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td>
<table cellpadding="0" cellspacing="5">
<tr>
<td style="padding: 5px;">
Lösenord:
</td>
<td>
<input name="pwd" type="password" class="required password" id="pwd">
</td>
<td>
En gång till..
</td>
<td>
<input name="pwd2" id="pwd2" class="required password" type="password">
</td>
<td>
<input name="doRegister" type="submit" id="doRegister" value="Register">
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
<script type="text/javascript">
$(function() {
$("#continue").click(function() {
$.ajax({
type: "POST",
url: "dbc.php",
data: {
check: 'First',
full_name: $('#full_name').val(),
usr_email: $('#usr_email3').val()
},
success: function(msg) {
if (msg == '1') {
$("#First_1").hide();
$("#Next_2").toggle();
} else {
alert(msg);
}
}
});
return false;
});
});
</script>
Thats my form. You fill 3 form elements to start with, then you press the Continue button, and then it sends ajax call to check the fields. If everythings OK (if output = 1 from ajax call), Next_2 gets toggled on, where you enter your password twice. After that you press on the final button Register, which should do "action=index.php?page=checkin", but it doesnt, when i press register it just get blank, and i can see in firebug that it sends another ajax call which i cannot understand because the button doesnt have id="continue" but id="doRegister"

Since the "Continue" button doesn't actually submit the form, try declaring it as a normal button instead of a submit button, like this:
<input type="button" id="continue" value="Fortsätt">
I'm guessing that having two submit buttons on the same form is somehow causing interactions with the handler.

I think you should make the "Continue" button as type="button" and not submit
<input type="button" id="continue" value="Fortsätt">

Related

PHP: cannot retrieve data from radio button POST

I'm having issues with retrieving data from the radio button. I can retrieve other data from the other html tags but in radio button I cannot. Why is that? Can you help me?
My HTML code is here:
<form enctype="multipart/form-data" name="markpayment" method="post" action="test.app">
<input type="hidden" name="action" value="mark_payment">
<input type="hidden" name="client-id" value="{$details[row]->id}">
<input type="hidden" name="invoice-id" value="{$details[row]->invoice_id}">
<input type="hidden" name="period" value="{$details[row]->period}">
<table width="100%" border="0" style="padding-top: 10px;">
<tr align="center">
<td class="radiobut">
<input type="radio" id="choice1" name="payment_status" value="paid"> Paid</td>
<td class="radiobut">
<input type="radio" id="choice2" name="payment_status" value="declined"> Declined</td>
</tr>
<tr align="center">
<td colspan="2">
<div class="paddingRow3">
<select class="selectbut" id="payments" name="payment-method">
<option value="Cheque">Cheque</option>
<option value="Deposit">Deposit</option>
<option value="Cash">Cash</option>
</select>
</div>
</td>
</tr>
<tr align="right">
<td colspan="2">
<div class="paddingRow3">
Update
</div>
</td>
</tr>
</table>
</form>
While my PHP script is here:
if($_REQUEST['action'] == 'mark_payment'){
echo '<pre>';
print_r($_REQUEST);
exit;
}
My output will be just like this:
Array
(
[NONCE] => f305790c4d8b060121b99fe84a8fdf1a62321b3b06b9097caa8439e2f9c5bae7
[action] => mark_payment
[client-id] => 2699422
[invoice-id] => 13008351
[period] => 11
[payment-method] => Cheque
)
You have duplicate name attributes of payment_status for your two choices. They need to be different, or only the last input element (#choice2) will be available.
I've gone with payment_status_paid and payment_status_declined in the following example, but you can also use the square bracket notation name="payment_status[]" to make an array of POST data.
<form enctype="multipart/form-data" name="markpayment" method="post" action="test.app">
<input type="hidden" name="action" value="mark_payment">
<input type="hidden" name="client-id" value="{$details[row]->id}">
<input type="hidden" name="invoice-id" value="{$details[row]->invoice_id}">
<input type="hidden" name="period" value="{$details[row]->period}">
<table width="100%" border="0" style="padding-top: 10px;">
<tr align="center">
<td class="radiobut">
<input type="radio" id="choice1" name="payment_status_paid" value="paid"> Paid</td>
<td class="radiobut">
<input type="radio" id="choice2" name="payment_status_declined" value="declined"> Declined</td>
</tr>
<tr align="center">
<td colspan="2">
<div class="paddingRow3">
<select class="selectbut" id="payments" name="payment-method">
<option value="Cheque">Cheque</option>
<option value="Deposit">Deposit</option>
<option value="Cash">Cash</option>
</select>
</div>
</td>
</tr>
<tr align="right">
<td colspan="2">
<div class="paddingRow3">
Update
</div>
</td>
</tr>
</table>
</form>
To find which one is chosen, use a conditional:
if($_REQUEST['action'] == 'mark_payment'){
echo '<pre>';
print_r($_REQUEST);
if ($_POST['payment_status_paid']) {
// Payment was successful
}
else {
// Payment was declined
}
exit;
}
Hope this helps!

neither required nor pattern is working in html

I am trying to validate the mobile number, email, firstname and etc.. field by using required and pattern keyword but its not responding anything.
In my program there is one input field for mobile number if user has entered mobile number which is not stored in database, then registration page pops up and user should registered for further process and if they entered mobile number which is stored in database then random number is displayed, but when I am entering the values in registration form but it is not validating like I have return required keyword in input field but still its not responding.
Please help me out of this.
Below us my code:
HTML
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<!DOCTYPE html>
<body>
<div>
<form action = "#" method = "post" >
<div>
<legend >Login</legend>
<table id="verify_table" cellpadding="2" cellspacing="2" >
<tr>
<td> Mobile No. </td>
<td><input id="mob" type="tel" name="mobile" required pattern="\[7-9]{1}[0-9]{9}\" /></td>
<td><input type="button" name="verify" class="verify" value="Verify"></td>
</tr>
</table>
</div>
<div id="random" style="display: none;" >
<table id='random_table'>
<tr>
<td>Random Number generated</td>
<td id='rand'>
</tr>
</table>
</div>
<!--Register pop up-->
<div id="reg_light" class="white_content">
<div id="register-title">
<div id="reg-title">
<h6>Register</h6>
</div>
<div id="close">
<a href="javascript:void(0)" onclick="document.getElementById('reg_light').style.display='none';
document.getElementById('fade').style.display='none'; $('#firstname').val('');
$('#lastname').val('');
$('#mobile_number').val('');
$('#email').val('');">X</a>
</div>
</div>
<?php //echo form_open('register'); ?>
<div id="register-inner">
<form id="reg_form" method="POST">
<table id="register_table">
<tr><td><font color="red">* Fields are mandatory</font></td></tr>
<!--<form id="reg_form" onSubmit="return formValidation();">-->
<tr>
<table id="name">
<tr>
<td>First Name<font color="red">*</font></td>
<td><input id="firstname" type="text" placeholder="First Name" name="firstname" required pattern="[A-Za-z]+" ></td>
<td>Last Name<font color="red" >*</font></td>
<td> <input id="lastname" type="text" placeholder="Last Name" name="lastname" required pattern="[A-Za-z]+"></td>
</tr>
</table>
</tr>
<tr><td>&nbsp&nbsp</td></tr>
<tr>
<table id="gen">
<tr>
<td>Gender<font color="red">*</font></td>
<td><input type="radio" name="gender" value="Male"> Male</td>
<td><input type="radio" name="gender" value="Female"> Female</td>
</tr>
</table>
</tr>
<tr>
<table id="mob">
<tr>
<td>Mobile No.<font color="red">*</font></td>
<td><input id="mobile_number" type="text" placeholder="Mobile number" name="mobile_number" required pattern="[7-9]{1}[0-9]{9}" /></td>
<td>Email id<font color="red">*</font></td>
<td> <input id="email" type="email" placeholder="Email-id" name="email" required pattern="[A-Za-z]+[0-9]+#[A-Za-z]+.[A-Za-z]+"> </td>
</tr>
</table>
<table id="submit">
<tr>
<td id="errorBox"></td>
<td><input class="reg_data" id="submit" type="button" name="submit" value="Register"></td>
</tr>
</table>
</tr>
</table>
</form>
</div>
</body>
</html>
Here is my jQuery code
$(document).ready( function() {
$('.verify').click(function(){
var mob = $('#mob').val();
//alert(mob);
$.ajax({
url: "<?php echo base_url(); ?>/login/verify",
data: {'mob_no': mob},
type: "post",
cache: false,
success: function (data)
{
//alert(data);
var obj = $.parseJSON(data);
var fi="";
var otp="";
var rand="";
rand+=Math.floor(100000 + Math.random() * 99999);
$.each(obj, function()
{
fi=this['id'];
});
if(!fi=="")
{
//document.getElementById("random").innerHTML=random_number;
$('#rand').val(rand);
document.getElementById("rand").innerHTML=rand;
document.getElementById('random').style.display='block';
}
else
document.getElementById('reg_light').style.display='block';
document.getElementById('fade').style.display='block';
//alert(fi);
}
},
error: function (xhr, ajaxOptions, thrownError) {
//alert(thrownError);
}
});
});
});
Reset the form validation, after making the form visible
function resetFormValidator(formId) {
$(formId).removeData('validator');
$(formId).removeData('unobtrusiveValidation');
$.validator.unobtrusive.parse(formId);
}
For Dynamically created dom
Use
$(document).on('click','#id',function(){
// do somethings
})

Not able to reset the input field jquery php wordpress

I need to reset the field onclick of reset button
But I am not able to do that.
Here is my html code
<table cellspacing="2" cellpadding="5" style="width: 100%;" class="form-table1" id="form-table1" >
<tbody>
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_mailCc"><?php _e('OpenLab Cc', 'custom_table_example')?></label>
</th>
<td>
<input id="approved_mailCc" name="approved_mailCc" type="email" value="<?php echo isset($item['approved_mailCc']) ? $item['approved_mailCc'] : ''; ?>"
size="50" class="code" placeholder="<?php _e('OpenLab Cc', 'custom_table_example')?>" required />
<input type="button" value="Reset" id="approved_mailCc" name="openLab"/>
</td>
</tr>
jQuery code
jQuery(document).ready(function($){
console.log("plugin script loaded2");
$('#approved_mailCc').click(function(){
$(this).val('');
});
});
1 I am getting console log.
2 alert is not going inside onclick
3 i used reset function also.
You have two inputs with the same ID of "approved_mailCc" you can't have more than one item with the same ID, it will confuse jQuery. Give them unique IDs like below:
<table cellspacing="2" cellpadding="5" style="width: 100%;" class="form-table1" id="form-table1" >
<tbody>
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_mailCc"><?php _e('OpenLab Cc', 'custom_table_example')?></label>
</th>
<td>
<input id="approved_mailCc_email" name="approved_mailCc" type="email" value="<?php echo isset($item['approved_mailCc']) ? $item['approved_mailCc'] : ''; ?>"
size="50" class="code" placeholder="<?php _e('OpenLab Cc', 'custom_table_example')?>" required />
<input type="button" value="Reset" id="approved_mailCc_button" name="openLab"/>
</td>
</tr>
and then use this jQuery code:
jQuery(document).ready(function(){
console.log("plugin script loaded2");
jQuery('#approved_mailCc_button').click(function(){
jQuery('#approved_mailCc_button_email').val('');
});
First, you are not supposed to need Javascript to reset a form (but you need the tag) :
https://jsfiddle.net/9xfonyou/
Second, there are errors on your code double IDs.
Here "approved_mailCc" is both your input file and your button. Then you can do this in Javascript to make it work.
HTML :
<form>
<table cellspacing="2" cellpadding="5" style="width: 100%;" class="form-table1" id="form-table1">
<tbody>
<tr class="form-field1">
<th valign="top" scope="row">
<label for="approved_mailCc"></label>
</th>
<td>
<input id="input_field" name="approved_mailCc" type="email" value="" size="50" class="code" placeholder="test" required />
<input type="reset" id="reset_button" name="openLab" />
</td>
</tr>
</tbody>
</table>
</form>
JS :
jQuery(document).ready(function($) {
console.log("plugin script loaded2");
$('#reset_button').click(function(e) {
e.preventDefault();
$('#input_field').val('');
});
});
https://jsfiddle.net/9xfonyou/1/

two submit buttons for the same form

Lets says that I have form and in the end I have 2 buttons
1 - send test form
2 - send live form
both send the same form. How can I send parameter to the server so I will know if its test or live?
Thanks
<form method='post' action='index.php?page=mailing&campID=<?PHP echo $_GET['campID'] ?>&act=<?PHP echo $actType ?>' id="Form" >
<table class="sort">
<tr>
<td>email address</td>
<td><input type="text" name="emailTest" value="<?PHP echo $user_details['email'] ?>" /></td>
</tr>
<tr>
<td></td>
<td>send test</td>
<td>send live</td>
</tr>
</table>
</form>
Just check in php if 'submit' field is 'test' or 'live'.
<form method='post' action='' id="Form" >
<table class="sort">
<tr>
<td>email address</td>
<td><input type="text" name="emailTest" value="" /></td>
</tr>
<tr>
<td></td>
<td><button type="submit" name="submit" value="test">Test</button></td>
<td><button type="submit" name="submit" value="live">Live</button></td>
</tr>
</table>
</form>
You'll either need to use JS, or one submit button, and a radio button. The latter is a better option, as you can't accidentally submit something to the wrong queue. Also, you should really be using a submit button, not an anchor.
The reason I would prefer the radio buttons is because once you click submit, you're past the point of no return. The radio button allows you to to click the wrong one, and then change it.
input[type="submit"] {
background: none;
border: 0;
color: blue;
text-decoration: underline;
cursor: pointer;
}
<form method='post' action='' id="Form">
<table class="sort">
<tr>
<td>email address</td>
<td>
<input type="text" name="emailTest" value="" />
</td>
</tr>
<tr>
<td>
<input type="radio" name="testLive" value="test" id="test" />
<label for="test">Submit as Test</label>
</td>
<td>
<input type="radio" name="testLive" value="live" id="live" />
<label for="live">Submit as Live</label>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Submit" />
</td>
</tr>
</table>
</form>

php:using two buttons inside same form and form submission

i am designing a login page using html and php.it includes two buttons one for login and another one to redirect to the registration page.i am planning to use php code to validate login data on the same page.here is my code
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post">
<div>
<table style="width: 100%; height: 377px;">
<tr>
<td rowspan="4"><img src="woman.jpg" height="100%" width="100%" alt="woman"/></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td align="right" style="padding:0px;color:white" >username:</td>
<td><input runat="server" name="Text1" type="text" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td align="right" style="padding:0px;color:white">password</td>
<td><input runat="server" name="Text2" type="text" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td></td>
<td ><input name="Submit1" type="submit" value="login" />
<input onclick="document.location.href='regforswa.php'" name="Submit2" type="submit" value="register" /><br/>
forgot password</td>
</tr>
</table>
</div>
</form>
but the button for registration is not working properly.it is not redirecting to the registration page.i don't want to put register button outside the form.i want to keep the same design and achieve required functionality.
Change the Button-Type from type="submit" to type="button" to disable the form submission:
<input onclick="document.location.href='regforswa.php'" name="Submit2" type="button" value="register" />

Categories