I am using this form on my php file to create the form
<input type="text" name="OrderLNumber" id="OrderLNumber" >
<br>
<input type="submit" name="submit" value="Status">
</form>
after that I am trying to pre-fill the form OrderLNumber field from this URL:
status/2727?OrderLNumber=24206927
Page loads normally but field is not filled as I intend to. How can I make this work ?
You need to get the order number from the url by using the $_GET['OrderLNumber'] variable.
The code below will test to see if the form has been submitted. If the from has loaded fresh with no POST data it will grab the order number from the url. If the form has been submitted and there is POST data it will use whatever is in the form for the order id.
Like so:
<?php
if(isset($_POST['OrderLNumber']) && $_POST['OrderLNumber']){
$orderLNumber = $_POST['OrderLNumber'];
}else{
if(isset($_GET['OrderLNumber']) && $_GET['OrderLNumber']){
$orderLNumber = $_GET['OrderLNumber'];
}
}
?>
<form action="" method="POST">
<input type="text" name="OrderLNumber" id="OrderLNumber" value=" <?php echo $orderLNumber; ?> " ><br>
<input type="submit" name="submit" value="Status">
</form>
Hope this helps.
Related
I am new with CodeIgniter and I want to pass hidden field value to another page using jQuery in CodeIgniter. Can I do this using jQuery?
<input type="hidden" name="grdtot" class="grdtot" />
this hidden field on cart.php page
<label id="grdtot_c" name="grdtot_c" class="grdtot_c"></label>
I want to fetch this hidden field value on checkout.php page. How I can do this using jQuery?
You can do this another way using localstorage to getting value from another page
Just write like this on page one.
localStorage.setItem('Gridtotal', $('.grdtot').val());
And get value from another page.
var grdTotal= localStorage.getItem('Gridtotal');
$('#grdtot_c').val(grdTotal);
Suppose You have form given below:
<body>
<div>Upload data to the server without page Refresh</div>
<input type="hidden" name="hidden_name" id="hidden_name">
<input type="text" name="name" id="name">
<input type="text" name="email" id="email">
<input type="text" name="website" id="website">
<input type="submit" name="submit" id="save" value="Submit">
<div id="display"></div>
</body>
And Now Your Script to send data to Your Controller.
You must have to use ajax to send data to the controller in CodeIgniter, And It will make your work easy.
<script>
$(document).ready(function(){
$('#save').click(function(){
var hidden_name = $('#hidden_name').val();
var name = $('#name').val();
var email = $('#email').val();
var website = $('#website').val();
$.ajax({
type:'POST',
url:'<?php echo base_url();?>index.php/controller_name/function_name',
async:false,
data:{
"done":1,
"hidden_name":hidden_name,
"name":name,
"email":email,
"website":website
},
success:function(data){
$('#display').html(data);
}
});
});
});
</script>
I have the following forms
<form name="courses">
<div="requiredfield">
<input type="text" name="coursename" id="coursename">
</div>
<input type="submit" name="submitform1">
</form>
<form name="students">
<div="requiredfield">
<input type="text" name="studentfirstname" id="studentfirstname">
</div>
<div="requiredfield">
<input type="text" name="studentlastname" id="studentlastname">
</div>
<div="requiredfield">
<input type="text" name="studentage" id="studentage">
</div>
<input type="submit" name="submitform2">
</form>
I use this code for client side validation
// this works fine
$('#courses').submit(e) {
e.preventDefault();
if ($('#coursename').val() == 0) {
// error message is appended to the div containing the field
// the same for the other form and its field
}
}
What does not work is the server side validation
<?php
if (isset($_POST['submitform1'])) {
if (empty($_POST['coursename'])) {
$course_mistake = "please fill this field"
}
}
?>
I have no idea why the server side validation does not work. Please help me.
<form name = "courses" method="post" action="validation.php">
// Your form fields.
</form>
You should specify the method and the name of php file in <form> , in which your controls will go on submit .
See this http://www.w3schools.com/php/php_forms.asp
1 You prevent form submitting:
$('#courses').submit(e) {
e.preventDefault(); // This prevents form submitting to PHP side
If you don't use Ajax (I don't see any code related), than you are note sending data to PHP
2 <form name="courses"> means you are using $_GET method, but in PHP you expect $_POST.
Either add method="post" or in PHP use $_GET/$_REQUEST.
3 You are not outputting errors nowhere - missing $course_mistake processing
Second image ,First image I have a set of links, which will open a pop-up form.
When the link is clicked,I want to send a parameter to the form and then use it on form submission.
I'm able to set the value to be passed as id of <a> tag. Can I send to further?
<div> <span>Chapter $i:</span>
<a href='$viewlink '>View</a><span class='status'>Status:$status </span>
<a href=$reqlink id=$i data-rel='popup' class='ui-btn ui-btn-inline ui-corner-all ui-icon-check ui-btn-icon-left'>Request Access</a></div><br/>";
<form method="post" action=" " id="myPopup" data-role="popup" style="padding:10px">
<h3>Enter your details</h3>
<input type="text" name="name" id="name" placeholder="Name" required>
<input type="email" name="email" id="email" placeholder="Email" required>
<input type="date" name="date" id="date" placeholder="Intended completion date" required>
<input type="submit" data-inline="true" value="Submit" name='submit'>
</form>
Is it possible to do in javascript? How to do it?
Option #1:
Set up hidden inputs, and send the values to them when clicking the link. You can then get these on the other end where the form is sent.
(Note: in my code examples I'm explicitly using PHP as that's where you seem to have copied your code snipped from)
echo "<a href='$viewlink' onclick='$(\'#viewlink\').val(1);'>View</a><span class='status'>Status:$status </span>
<!-- Do the following inside the form -->
<input type='hidden' name='viewlink' id='viewlink' value='0' />";
And on the PHP receiving end you can do this:
if ($_POST['viewlink'] == 1) {
// do stuff
}
Option #2:
Alternatively you could send the data to a javascript array, prevent posting on submit of the form, take care of adding the array to the form action as query string, then explicitly send the form.
echo "<a href='$viewlink' onclick='linkClicked('viewlink');'>View</a><span class='status'>Status:$status </span>
This is what you'd do in your javascript file:
var queryString = [];
function linkClicked (type) {
queryString[type] = 1;
}
$("#myPopup").submit(function(event) {
event.preventDefault();
$(this).attr('action', $(location).attr('host') + $.param(queryString));
$(this).submit();
});
And on the PHP receiving end you can do the following (note the $_POST from above has changed to $_GET):
if ($_GET['viewlink'] == 1) {
// do stuff
}
try this..
<a id = 'yourid' class = 'mybtn'>click me..</a>
<form id = 'myform'>
....
</form>
Jquery
$(document).ready(function(){
$('.mybtn').click(function(){
var id = $(this).attr('id');
var SubmitForm = $("#myform").serializeArray();
$.post("somepage.php",
{
SubmitForm:SubmitForm,
ID:id
},
function(res){
alert(res);//your result..
});
});
i am trying to check my value form database it already enter or not before submitting the form
i have code its display the result in text box how it is possible that result is display in div or span.
my code is as under:
my first file category.php have script and html form
script
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#id").keyup(function() {
$.ajax({
type : "POST",
url : "dbscript2.php",
data : "id=" + $("#id").val(),
success : function(html) {
$("#message").val(html);
}
});
});
});
</script>
html form is :
<form method="POST" action="gcd.php">
<p>
<label>Category:</label>
<input type="text" name="category" id="id" tabindex="1" />
</p>
<p>
<div id="mes"></div>
<input type="text" name="new" id="message" tabindex="2" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Save" />
</p>
</form>
and last php file message dbscript2.php
<?php
include "config.php";
$id = $_POST['id'];
$q=mysql_query("select * from category where category ='$id'");
$num=mysql_num_rows($q);
if($num==0)
echo "";
else
{
echo "This Category already Entered";
}
?>
Since there are couple of errors in the actual code you shared and the answer you derived, let me put it across here
HTML form
<form method="POST" action="gcd.php">
<p>
<label>Category:</label>
<input type="text" name="id" id="id" tabindex="1" />
</p>
<p>
<div id="mes"></div>
<input type="text" name="message" id="message" tabindex="2" />
</p>
<p>
<input type="submit" name="submit" id="submit" value="Save" />
</p>
</form>
The core code where you want the data to get inserted to the div
$("#mes").text(html);
Please note that you get the value returned from the php script, and not some html. Hence it is better to rename your expected return value as some other identifier say mydata
$("#mes").text(mydata);
Please let me know if you are looking for something else.
Updated based on OP's further query
Please read jquery API docs, It gives you an idea of the supported functions http://api.jquery.com/.
To your specific question, yes you can hide or show a particular div using the below calls:
//check your condition and show or hide the div accordingly
$("#mydiv").show();
or
$("#mydiv").hide();
i am having a Form like
<script language="javascript" type="text/javascript">
function formfn()
{
var str = document.getElementById('TitleSearch').value;
alert(str);//displays the keyword like database
}
</script>
<form name="f1" method="post">
<p><label for="TitleSearch">Keywords:</label>
<input title="Keyword" size="40" value="" id="TitleSearch"></p>
<p>
<input type="submit" id="im-search" value="Search" name="im-search" onClick="formfn();"></p>
</form>
I am having a page where in the top i have this form on search it has to take the value of the textbox TitleSearch and to use this to retrieve the records matching by
<?php
$db =& JFactory::getDBO();
$query = 'SELECT * from #__chronoforms_Publications where keyword like "%valueretrieved%" ';
$db->setQuery($query);
$rows = $db->loadObjectList();
//echo $rows;
?>
Once the search button is clicked the text box value of the keyword is retrieved .
I am trying to use this value in the select query to fetch the records and to display in the same page..
How to do so..
Pls change the button type
Here is the modified code:
<script language="javascript" type="text/javascript">
function formfn()
{
var str = document.getElementById('TitleSearch').value;
alert(str);
}
</script>
<form name="f1" method="post">
<p><label for="TitleSearch">Keywords:</label>
<input title="Keyword" size="40" value="" id="TitleSearch"
name="TitleSearch"></p>
<p> <input type="button" id="im-search" value="Search" name="im-search"
onClick="formfn();"></p>
</form>
You need to look into AJAX
Here is the simple version from w3schools
http://www.w3schools.com/PHP/php_ajax_database.asp
alternative is jQuery:
The first of the links here can get you to the next step - google for
php ajax jQuery
This is AJAX database.
See
http://www.w3schools.com/php/php_ajax_database.asp
which gives a really specific details. You need a separate PHP page to call your DB.
I did this function before. Just make sure your PHP page is not accessible and safe enough.