Hide text box before fetch data from mysql - javascript

i want that only text filed of student registration and button show on page then Student put their number in text field and clink on Submit button so the other all fields are fetch from database sql
but but but i done all only the problem is here that on php page all things are show already like text boxes i want only one text box and submit button on page before fetch the data .
after fetch the data from mysql database the other fields text boxes will Show
here my code
<div class="container">
<form id="contact" form action="mix.php" method="post">
<fieldset>
<input type="text" name="student_reg" required="required" placeholder="Student Registration Code" value="<?php echo $student_reg;?>">
</fieldset>
<div>
<!-- Input For Add Values To Database-->
<!-- Input For Find Values With The given ID -->
<input type="submit" class="myButton" name="search" style="width:100%;" value="Find">
</div>
<fieldset>
<input type="text" name="student_name" placeholder="Name" style="border:0;outline:none;width:100%;height:100%;font-size:13px;text-align: left;" value="<?php echo $student_name;?>" readonly>
</fieldset>
<fieldset>
<input type="text" name="phone_number" placeholder="Phone Mobile Number" style="border:0;outline:none;width:100%;height:100%;font-size:13px;text-align: left;" value="<?php echo $phone_number;?>" readonly>
</fieldset>

try this:
<div class="container">
<form id="contact" form action="mix.php" method="post">
<fieldset>
<input type="text" name="student_reg" required="required" placeholder="Student Registration Code" value="<?php echo $student_reg;?>">
</fieldset>
<div>
<!-- Input For Add Values To Database-->
<!-- Input For Find Values With The given ID -->
<input type="submit" class="myButton" name="search" style="width:100%;" value="Find">
</div>
<?php if(!empty($student_name)) { ?>
<fieldset>
<input type="text" name="student_name" placeholder="Name" style="border:0;outline:none;width:100%;height:100%;font-size:13px;text-align: left;" value="<?php echo $student_name;?>" readonly>
</fieldset>
<fieldset>
<input type="text" name="phone_number" placeholder="Phone Mobile Number" style="border:0;outline:none;width:100%;height:100%;font-size:13px;text-align: left;" value="<?php echo $phone_number;?>" readonly>
</fieldset>
<?php } ?>

Related

Disable submit button once the user submits the form

I am using the PHP & MySQL to submit a form with following code and using isset function in PHP to submit the value to database.
<div class="display">
<form action="" method="POST">
<div>
<input type="text" name="name" placeholder="Your Name" required="required">
</div>
<div>
<input type="text" name="phone" id="phone" placeholder="Mobile" required="required" onblur="check();">
<br/>
<span id="e_mobile"></span>
<?php if(isset($_GET["r"])){ ?><p>Invalid number; must be ten digits. Please submit your query again</p><?php } ?>
</div>
<div>
<input type="text" name="landline" id="landline" placeholder="Alternate Number" required="required" onblur="check1();">
<br/>
<span id="e_landline"></span>
</div>
<div>
<input type="email" name="email" placeholder="Email" required="required">
</div>
<div>
<input type="text" name="address" placeholder="Your Address" required="required">
</div>
<div>
<input type="hidden" value="0" name="salesid"/>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</div>
Now I want once the user click submit button once the button should freeze; as of now if the user clicks the submit button more than once(by intentionally or by mistake) the same information is getting submitted in the database more than once.
What to do in this circumstance?
Try with JQuery:
First add an ID to your form
<form action="" method="POST" id="form">
After that add script:
<script type="text/javascript">
$(document).ready(function() {
$("#form").submit(function(e){
$("input[type='submit']").attr("disabled","disabled");
});
});
</script>
You can add PHP Captcha to prevent user click again.
Please review below two urls which includes demo too.
http://www.w3schools.in/php/captcha/
http://99webtools.com/blog/php-simple-captcha-script/

jQuery: How to get the object of the form who's submit button was clicked?

I've multiple forms in my html based web page. I have a 'Submit' button on each of the form. Whenever I fill a form and click on it's submit button, I want to know which form was submitted. Means, upon pressing a submit button I want to know the details of the associated form (all forms have the similar button).
Stuff like getting the entire form object or id or name of the submitted form will also work.
My JQuery code is :
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$( "form" ).submit(function () {
var val = $("input[type=submit][clicked=true]").val();
(1) console.log(val);
});
$("form input[type=submit]").click(function() {
$("input[type=submit]", $(this).parents("form")).removeAttr("clicked");
$(this).attr("clicked", "true");
});
});
</script>
My html code containing the forms is:
<!-- This is form number 1 -->
<form align="center" class="nav nav-list" id="myFormCS" method="POST" action="#" > <!-- <- I want this info -->
<p> <input type="hidden" name="productid" value="4"> </p>
<p> <input type="hidden" name="version" value="1"> </p>
<p> <input id="field_email" type="email" placeholder="Enter email address" name="eml1" required></p>
<p> <input id="field_pwd1" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" placeholder="Enter password" name="pwd1" required> </p>
<div class="pricing-footer">
<input class="btn-submit-modal" type="submit" value="Free"> **<-- (1) is getting me this info**
<input class="btn-modal" type="button" onclick="closeRegistration()" value="Close">
</div>
</form>
<!-- This is form number 2 -->
<form align="center" class="nav nav-list" id="myFormGE" method="POST" action="#" >
<p> <input type="hidden" name="productid" value="14"> </p>
<p> <input type="hidden" name="version" value="1"> </p>
<p> <input id="field_username" type="text" placeholder="Enter user name" name="usrnm" required></p>
<p> <input id="field_pwd1" type="password" required pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}" placeholder="Enter password" name="pwd1" required> </p>
<div class="pricing-footer">
<input class="btn-submit-modal" type="submit" value="Register">
<input class="btn-modal" type="button" onclick="closeRegistration()" value="Close">
</div>
</form>
<!-- This is form number 3 -->
<form align="center" class="nav nav-list" id="myFormVI" method="POST" action="#" >
<p> <input type="hidden" name="productid" value="7"> </p>
<p> <input type="hidden" name="version" value="2"> </p>
<p> <input id="field_city" type="text" placeholder="Enter city name" name="city1" required></p>
<p> <input id="field_phone" type="text" placeholder="Enter phone number" name="phn1" required> </p>
<div class="pricing-footer">
<input class="btn-submit-modal" type="submit" value="Buy now">
<input class="btn-modal" type="button" onclick="closeRegistration()" value="Close">
</div>
</form>
Something like this?
$("form input[type=submit]").click(function() {
var frmID = $(this).closest('form').attr('id');
alert(frmID);
});
jsFiddle
You can use a submit listener for the form and get the object. Something like this:
$("form").submit(function (e) {
e.preventDefault();
var form = $(this);
console.log(form);
});
That form object is what I think you are looking for.

How to keep discussions of user in database and show them on view page

I have a problem in my crm application,in my application I have a user view page with his details and a add follow up button in which I have 3 text fields used to maintain follow-up records of a user and show dis follow-up details in view page . How can I achieve it?
Here's my view.php page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<?php require_once ("sqlremote.php");
$sql="Select * from ac_member order by rand() limit 15";
$res=$db->prepare($sql);
$res->execute();
$row = $res->fetch(PDO::FETCH_ASSOC)
?>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="css/default.css"/>
<script type="text/javascript" src="js/script.js"></script>
<script type="text/javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}
</script>
<style>
.top-section{height:87px; padding-bottom:10px;}
.logo{width:266px; height:87px; float:left;}
body {
background-image: url(images/hd_wall_4472.jpg);
</style>
</head>
<body oncontextmenu="return false">
<div class="logo"><img src="images/logo.png" alt="" width="200" height="78" border="0" /></div>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
</br>
<form action="process.php" method="post" class="register">
<fieldset class="row1">
<legend>Basic Information</legend>
<p>
<label>Date
</label>
<input name="fname" type="text" readonly="readonly" value="<?php echo $row['datepicker']?>"/>
<label>Full Name
</label>
<input type="text" readonly="readonly" value="<?php echo $row['fname'] ?>"/>
<label>Qualification
</label>
<input type="text" readonly="readonly" value="<?php echo $row['qualification'] ?>"/>
</p>
<p>
<label>Father Name
</label>
<input type="text" readonly="readonly" value="<?php echo $row['gname'] ?>"/>
<label>Email
</label>
<input name="contact" type="text" readonly="readonly" value="<?php echo $row['email'] ?>"/>
<label>Contact
</label>
<input name="contact" type="text" readonly="readonly" value="<?php echo $row['contact'] ?>"/>
</p>
<p>
<label>City
</label>
<input type="text" readonly="readonly" value="<?php echo $row['city'] ?>"/>
<label>Course
</label>
<input type="text" readonly="readonly" value="<?php echo $row['course'] ?>"/>
</p>
<div class="clear"></div>
</fieldset>
</br></br>
<fieldset class="row1">
<legend>Lead Info</legend>
<p>
<label>Lead Source
</label>
<input name="leadsource" type="text" readonly="readonly" value="<?php echo $row['leadsource']?>"/>
<label>Lead Source Type
</label>
<input type="text" readonly="readonly" value="<?php echo $row['leadsourcetype'] ?>"/>
</p>
<p>
<label>Lead Source Detail
</label>
<input type="text" readonly="readonly" value="<?php echo $row['leadsourcedetail'] ?>"/>
<label>Lead Score
</label>
<input name="leadscore" type="text" readonly="readonly" value="<?php echo $row['leadscore']?>"/>
</p>
<div class="clear"></div>
</fieldset>
<fieldset class="row2">
<legend>Followup Details</legend>
<p>
<input type="button" value="Add Followup" onClick="addRow('dataTable')" />
<input type="button" value="Remove Followup" onClick="deleteRow('dataTable')" />
</p>
<table id="dataTable" class="form" border="1">
<tbody>
<tr>
<p>
<td><input type="checkbox" required="required" name="chk[]" checked="checked" /></td>
<td>
<label>Followup</label>
<input type="text" required="required" name="BX_NAME[]">
</td>
<td>
<label for="BX_age">Followup Calldisposition</label>
<input type="text" required="required" name="BX_age[]">
</td>
<td>
<label for="BX_gender">Followup Comments</label>
<input type="text" name="BX_gender[]" required="required">
</td>
</p>
</tr>
</tbody>
</table>
<div class="clear"></div>
</fieldset>
<input class="submit" type="submit" value="Confirm ยป" />
<div class="clear"></div>
</form>
</br>
</body>
<!-- Start of StatCounter Code for Default Guide -->
<script type="text/javascript">
var sc_project=9046834;
var sc_invisible=1;
var sc_security="ec55ba17";
var scJsHost = (("https:" == document.location.protocol) ?
"https://secure." : "http://www.");
document.write("<sc"+"ript type='text/javascript' src='" +
scJsHost+
"statcounter.com/counter/counter.js'></"+"script>");
</script>
<noscript><div class="statcounter"><a title="free hit
counter" href="http://statcounter.com/" target="_blank"><img
class="statcounter"
src="http://c.statcounter.com/9046834/0/ec55ba17/1/"
alt="free hit counter"></a></div></noscript>
<!-- End of StatCounter Code for Default Guide -->
</html>
Im not sure if i understand your question correct. Is this a database/query related issue or more a strategic question of what is considered best practise?
Im not really sure what youre trying to accomplish here :)
Ah :)
So actually you would grab your data gotten from you select first. Which you are already doing.
process.php:
if ($everythingisok) {
$res=$db->prepare("UPDATE ac_member SET bx_gender='".$_POST["BX_gender"]."', field2=etc... WHERE id = '".$_POST['id']."'");
$res->execute();
}
After storing the data into the table you can add to your html/view:
<input type="text" name="BX_gender" value="<?php echo escape($row['bx_gender']);?>" required="required">
However, i noticed that you are using the brackets in your input name. This will cause that the data coming through is passed as an array. I don't know if you did this on purpose

Javascript do not submit form TRUE

<script type="text/javascript">
function myFunction(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();}
</script>
<form id="form1" action="php/create.php">
Name </br><input type="text" name="inputName" value="" id=""> </input>
Hemsida </br><input type="text" name="inputPage" value="http://" id=""> </input>
<input type="button" onclick="return myFunction()" value="Submit"/>
</form>
<form id="form2" action="php/createhemerb.php">
<input type="text" name="inputFon" value="" id="fnid" hidden/>
<input type="text" name="inputJob" value="" id="fnid" hidden/>
</form>
I reach out to the php files but the both come out "please fill out the form 1" and "please fill out the form 2"
if(!$_POST['submit']) {
echo "please fill out the form";
header ('Location: please fill out the form 1');}
I have tried things back and fourth for hours i can not get it to work.
Please do the following to fix your issue:
Add method='post' to your forms
If you intend to check the value of $_POST['submit'], you need to name your button 'submit'.
You can't use echo and then header(''), it will set a 'header already sent exception'.
header('Location: some text') has no meaning, header('Location: file.html') is the correct syntax.
Full code:
<script type="text/javascript">
function myFunction(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
</script>
<form id="form1" action="php/create.php" method="post">
Name </br><input type="text" name="inputName" value="" id=""> </input>
Hemsida </br><input type="text" name="inputPage" value="http://" id=""> </input>
<input type="button" onclick="return myFunction()" value="Submit" name="submit"/>
</form>
<form id="form2" action="php/createhemerb.php" method="post">
<input type="text" name="inputFon" value="" id="fnid" hidden/>
<input type="text" name="inputJob" value="" id="fnid" hidden/>
</form>
PHP:
if(empty($_POST) || !$_POST['submit']) {
echo "please fill out the form";
//you can't set the header after echoing
//header ('Location: please fill out the form 1');//use header('Location: error.html') instead.
//or output a Javascript redirect echo "<script>window.location = 'error.html';</script>";
}
Hope this helps!

Sending Dual Forms with one submit, while pulling the email field from first Form into the second

I have two forms I need to send - the first form is a PHP mailer that takes the info from a bunch of fields and mails it to a recipent. That form has a checkbox and if checked I need the email from that for to be sent via ANOTHER form to a list server adding them to mailing list. I need all this to happen when clicking the submit button from the first form. Can anyone help me with a solution. Thanks.
Form
<form class="form_1" method="post" enctype="multipart/form-data" onSubmit="return validate()">
<div class="field">
<div class="text2">
<input type="text" id="name" value="<?php echo $_POST['name'];?>" name="name" title="Name" />
</div>
<!--text2-->
<div class="req">*</div>
<!--req-->
</div>
<!--field-->
<div class="field field_right">
<div class="text2">
<input type="text" id="email" name="email" value="<?php echo $_POST['email'];?>" title="Email" />
</div>
<!--text2-->
<div class="req">*</div>
<!--req-->
</div>
Sign-up for newsletter
Upload Resume:
<div class="clearer"></div>
<br />
<div class="field">
<input type="submit" value="Send" class="btn3" />
</div>
<!--field-->
</form>
Form 2
<form action="http://www.example.com/mailing_list.html" method="post" name="xxxxxxx" onSubmit="return (!(UPTvalidateform(document.UPTmxxxxxx)));">
<input type="hidden" name="submitaction" value="3">
<input type="hidden" name="mlid" value="xxxxxx">
<input type="hidden" name="siteid" value="xxxxxx">
<input type="hidden" name="tagtype" value="q2">
<input type="hidden" name="demographics" value="-1">
<input type="hidden" name="redirection" value="http://www.xxxx.com/thankyou.php">
<input type="hidden" name="uredirection" value="http://">
<input type="hidden" name="welcome" value="">
<input type="hidden" name="double_optin" value="">
<input type="hidden" name="append" value="">
<input type="hidden" name="update" value="on">
<input type="hidden" name="activity" value="submit">
<tr><td colspan="2"></td></tr><tr><td> </td><td> <div class="text1"><input type="text" name="email" id="email" />
</div></td></tr><tr><td colspan="2"><button type="submit" name="send" value="send" class="button1"></button></td></tr>
On your form, have the button tie back to a javascript event
<input type = 'button' value='Submit!' onclick='submitForms()' />
Then have that javascript function, submitForms, actually submit both of your forms.
document.forms["form1"].submit();
document.forms["form2"].submit();
You will probably need to do the second submission using PHPs curl wrapper so that you only have one form for the user to fill in. Is there any reason you must have two forms?
So it would work like this:
User submits form
Code sends first email
If checkbox checked then submit curl request to second form
Complete
A recent SO answers contains a simple intro to the curl post request process: How to issue HTTP POST request?

Categories

Resources