I have this simple form
<form action="" method="post" class="smart-green">
<h1>Contract Form
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Client:</span>
<input type="text" name="client" placeholder="Your Client Name" />
</label>
<label>
<span>Your Name (Salesman):</span>
<input type="text" name="salesman" placeholder="Name" />
</label>
<label>
<span>Construction Name:</span>
<input type="text" name="construction" placeholder="Construction Name" />
</label>
<label>
<span>City:</span>
<input type="text" name="city" placeholder="City" />
</label>
<label>
<span>Items:</span>
<input type="text" name="id_item" placeholder="Item" />
</label>
<label>
<span> </span>
<input type="button" class="button" value="Send" />
</label>
</form>
It is a form for orders. I need to be able to enter a value of items I am going to enter (5 for example) and then I need the "Items" input to appear 5 times. I also need to be able to remove it, so user can correct himself. I don't know how to code in Javascript, so is this even possible? How? I need to access it later as an array in my controller. Thats why I have the name of the field as an array. Thank you in advance for your help.
EDIT: I have just found something similiar to what I need here: http://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery
I just dont want it to be a button, but a field with a input for a number and for it to not have a limit. I wish I knew Javascript :<
EDIT2: Maybe I wrote it unclear, but I CAN use Javascript, I just dont know how to properly programm in it, so if anyone knows how to achieve that in Javascript, I would be glad.
It sounds like you need to ask the user how many items to order, then when the user submits the page to you, save the form data into an array using $_SESSION. The next page that is shown would provide the item text elements for the user to complete.
You'll basically want to:
Start session
If $_POST['id_item'] is set
Save all variables into $_SESSION
Generate item inputs based on id_item using a for loop
If items are provided
Retrieve previous form data from $_SESSION, marry with new item information
Otherwise
Display initial form
(Personal note: Javascript would make this much nicer and easier)
Without a scripting language, I don't believe this is possible. I suppose you could use simpler 'inline' scripts to do display subsequent elements, like:
<div id="item1div">
Item 1:<input name="item1" value="" onFocus="getElementById('item2div').style.display='block';">
</div>
<div id="item2div" style="display:none;">
Item 2:<input name="item2" value="" onFocus="getElementById('item3div').style.display='block';">
</div>
...
<div id="item10div" style="display:none;">
Item 10: <input name="item10" value="">
</div>
This would display each item as the previous item was selected. It comes with its own problems, and it's a real simplification of what you're asking, but it would accomplish your basic goal without having to write a function in JS.
Here is what I was referring to when I said use sessions + PHP. You can do this all in PHP, though javascript would be optimal. I have not included a way to remove the session inputs, however using other form elements will suffice. Also, I have not done any echoing values on reload. This is only an option if you really do not want to use javascript:
<?php
// Put at top of page
session_start();
// Also somewhere at top of page
// Check post empty and assign post to a session for continual use
if(!empty($_POST)) {
$_SESSION['form'] = $_POST;
} ?>
<form action="" method="post" class="smart-green">
<h1>Contract Form
<span>Please fill all the texts in the fields.</span>
</h1>
<label>
<span>Client:</span>
<input type="text" name="client" placeholder="Your Client Name" />
</label>
<label>
<span>Your Name (Salesman):</span>
<input type="text" name="salesman" placeholder="Name" />
</label>
<label>
<span>Construction Name:</span>
<input type="text" name="construction" placeholder="Construction Name" />
</label>
<label>
<span>City:</span>
<input type="text" name="city" placeholder="City" />
</label>
<label>
<span>Items:</span>
<input type="text" name="id_item" placeholder="Item" />
</label>
<label for="new">Add Fields</label>
<select name="new" id="new">
<option value="">Select</option>
<option value="1">Add 1</option>
<option value="2">Add 2</option>
<option value="3">Add 3</option>
<option value="4">Add 4</option>
</select>
<?php
// This checks if new has been posted
if(isset($_POST['new']) && $_POST['new'] >= 1) {
// Check if there are inputs in the queue
$count = (isset($_SESSION['form']['new_input']) && !empty($_SESSION['form']['new_input']))? count($_SESSION['form']['new_input']):1;
// Loop
for($i = $count; $i <= $_POST['new']+$count; $i++) { ?>
<input type="text" name="new_input[<?php echo $i; ?>]" id="new-<?php echo $i; ?>" />
<?php }
}
// Loop through sessioned inputs
if(isset($_SESSION['form']['new_input'])) {
$i = 0;
foreach($_SESSION['form']['new_input'] as $key => $value) { ?>
<input type="text" name="new_input[<?php echo $key; ?>]" id="new-<?php echo $key; ?>" value="<?php echo strip_tags($value); ?>" />
<?php }
} ?>
<button name="add_new" value="new">Add New</button>
<label>
<span> </span>
<input type="button" class="button" value="Send" />
</label>
</form>
Related
I am have three servers in three different domains. For example,
google.com
oracle.com
sap.com
I have a combo box with the same values as above. How can I change the form action to change to respective site once it is selected in the combo box?
Here is the code i have tried.
<script src="http://code.jquery.com/jquery-latest.min.js"
type="text/javascript"></script>
<script>
$(document).ready(function(){
$("#serverName").on("change",function(){
alert($(this).val());
if($(this).val().toString===("google"))
$("#dataform").attr('action',"http://google.com");
if($(this).val().toString===("oracle"))
$("#dataform").attr("action","http://oracle.com");
if($(this).val().toString===("sap"))
$("#dataform").attr("action","http://sap.com");
});
});
</script>
My form is like :
<form action="anyaction" name="dataform" method="post" >
<img src="logo.png"><br/>
<label for="email" class="boldtext">Triggered By</label><br>
<input type="text" id="email" name="email" placeholder="Enter your mail id"
required><br/>
<label for="serverName" class="`boldtext`">Server Name</label>
<select id="serverName" name="serverName" >
<option value="selectServer">Select the Server</option>
<option value="google">Google</option>
<option value="oracle" >Oracle</option>
<option value="sap">SAP</option>
</select><br/>
<label for="Clients" name= "Clients"
class="boldtext">Clients</label><br>
<input type="text" id="count" name="count"
placeholder="Enter No Of clients" required>
<br/>
<label for="items" name="items" id="items"
class="boldtext">Items</label>
<textarea id="items" name="items" required rows="3"> </textarea><br/>
<button type="submit">Submit</button>
</form>
Looks like there is some value represented by the name for the form i used "dataform".
Once i change it to dataform123 it worked. also the comparison i have changed from tostring.equals to == / === both of them worked.
Thanks for being there to keep me trying !!
I'm designing an attendance register system which will display all 'gymnasts' from the value set in a 'select class' dropdown with their own checkbox (Displaying this using AJAX and JSON). Which is all 'hunky dory'.
Pseudo Form:
<form>
<classes dropdown populated from classes table onchange="ajaxFunction()">
<save button>
</form>
Pseudo AJAX response: form elements of gymnasts with checkboxes next to them.
GymnastName [Checkbox]
GymnastName [Checkbox]
GymnastName [Checkbox]
GymnastName [Checkbox]
GymnastName [Checkbox]
GymnastName [Checkbox]
The user would then check the boxes of all the gymnasts that are present, and leave the boxes for the gymnasts that are absent.
Upon hitting the save button; I'm not sure how to go about saving each gymnast's presence as a single record in the class-attendance table:
class-attendance(id, classid, gymnastid, present[y/n],datetime)
I understand that this may not be the best way to approach the problem, however is there some way to create an array for the data contained in the form so that it can be inserted into the class-attendance table with each gymnast's presence being saved as a record?
Thanks for your help in advance!
what i understand according to that i have made script using HTML,Jquery and PHP. See the code is work for you or not.
HTML and Jquery Code
<form action="process.php" method="post">
<div>
GymnastName <input type="checkbox" class="atd" ><br>
<!-- put gymnastid in value what you getting from JSON -->
<input type="hidden" name="Gymnast_id[]" value='1' class="atdid">
<input type="hidden" name="Gymnast_attend[]" value='n' class="atdval">
</div><br>
<div>
GymnastName <input type="checkbox" class="atd"> <br>
<input type="hidden" name="Gymnast_id[]" value='2' class="atdid">
<input type="hidden" name="Gymnast_attend[]" value='n' class="atdval">
</div><br>
<div>
GymnastName <input type="checkbox" class="atd"> <br>
<input type="hidden" name="Gymnast_id[]" value='3' class="atdid">
<input type="hidden" name="Gymnast_attend[]" value='n'class="atdval">
</div><br>
<div>
GymnastName <input type="checkbox" class="atd"> <br>
<input type="hidden" name="Gymnast_id[]" value='4' class="atdid">
<input type="hidden" name="Gymnast_attend[]" value='n'class="atdval">
</div><br>
<div>
GymnastName <input type="checkbox" class="atd"><br>
<input type="hidden" name="Gymnast_id[]" value='5' class="atdid">
<input type="hidden" name="Gymnast_attend[]" value='n' class="atdval">
</div><br>
<input type="submit" name="Save">
</form>
<script
src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.atd').change(function() {
if($(this).is(":checked")) {
$(this).closest('div').find('.atdval').val('y');
}
else{
$(this).closest('div').find('.atdval').val('n');
}
});
});
<script>
PHP CODE (process.php)
<?php
$Gymnast_id=$_POST['Gymnast_id'];
$Gymnast_attend=$_POST['Gymnast_attend'];
foreach ($Gymnast_id as $key => $id) {
echo "Id: ".$id."<br>";
echo "Attend: ".$Gymnast_attend[$key]."<br><hr>";
// here you get id of Gymnast and present status, default it is "n"
// you can add your sql query here
//class-attendance(id, classid, gymnastid, present[y/n],datetime)
}
?>
I generate table from database, assign each cell as checkbox value, group each row as form and display them all as table refer to [this].1 How I can get particular cell value when i click on the button since each form (row) have a same id. I want to pass the value as query parameter to update the database table. I have searched for similar technique and still not find the solution.
This code is within a cursor fetching loop:
<form class="tr" id="barisn" method="post" action="">
<span class="td"><input type="checkbox" name="id" value="<?php $data[0]?>"/><label for="id"><?php echo $data[0]?></label></span>
<span class="td"><input type="checkbox" name="name" value="<?php $data[1]?>" /><label for="name"><?php echo $data[1]?></label></span>
<span class="td"><input type="checkbox" name="gender" value="<?php $gender?>" /><label for="gender"><?php echo $gender?></label></span>
<span class="td"><input type="checkbox" name="sender" value="<?php $data[8]?>" /><label for="sender"><?php echo $data[8]?></label></span>
<span class="td"><input type="checkbox" name="date" value="<?php $data[5]?>" /><label for="date"><?php echo $data[5]?></label></span>
<span class="td"><input type="checkbox" name="time" value="<?php $data[6]?>" /><label for="time"><?php echo $data[6]?></label></span>
<span class="td"><input type="checkbox" name="state" value="<?php $state?>" /><label for="state"><?php echo $state?></label></span>
<div class="td">
<button class="btn-rawuh" type="submit" form="barisn" value="Rawuh">Rawuh</button>
<button class="btn-tundha" type="submit" form="barisn" value="Tundha">Tundha</button>
<button class="btn-mlebet" type="submit" form="barisn" value="Mlebet">Mlebet</button>
</div>
</form>
You have to put anchor tag instead of button like this
Edit
when you click on edit button then page will redirect to edit.php(you have to create new php file) then get the id from url :
echo $_GET method
then u will get the details of that particular row using id (using query).
I have two input Fields same value one input fields have home page and another input fields same value have in results page.when i input the value in homepage this automatically Fill results page .if i enter value in home page 5000. this value automatically fill in same input fields Results page ? how i will do this ? please help me ?
code :
<div class="col-md-6">
<div class="glyphicon glyphicon-exclamation-sign gly pull-left">
</div>
<br />
<p>Confirm 1st Mortgage For DPA Scenario</p>
<div class="row">
<div class="col-md-12">
<select id="Select9" class="dropdown">
<option value="">Work with All Mortgages</option>
</select>
</div>
</div>
<br />
<br />
<p class="pull-right">DPA Minimum Buyer Contribution<br />
(Unless Included In Down Payment)
</p>
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6" style="padding-right:1%">
<input type="text" class="txt"/></div>
<div class="col-md-3" style="padding-left:0%">
<select id="Select10" class="dropdown"style="margin-top:1px">
<option value="">%</option>
</select></div>
</div>
</div>
In response to your comment:
i am using javascript server side in php
You would use server-side code to accomplish this. Let's look at a contrived example. On the first page, you might have a simple form:
<form method="post" action="secondPage.php">
<input type="text" name="myValue" />
<input type="submit" />
</form>
When submitting this form, the value in myValue is posted to the server-side code in secondPage.php. That page can access the value:
$myValue = $_POST['myValue'];
Then to output it to the page, you would echo (a sanitized version of) the value:
echo htmlspecialchars($myValue);
This can happen anywhere in your markup. For example, if you want it to be in another form element:
<input type="text" name="myValue" value="<?php echo htmlspecialchars($myValue); ?>" />
I am trying to modify a joomla component and more specific a questionnaire that contains radio buttons. In php file the code is :
<form id="form-table" action="<?php echo JRoute::_('index.php?option=com_bisbas&task=table.save'); ?>" method="post" class="form-validate" enctype="multipart/form-data" target="iframe1">
<ul>
<input type="hidden" name="jform[id]" value="<?php echo $this->item->id; ?>" />
<input type="hidden" name="jform[state]" value="<?php echo $this->item->state; ?>" />
<?php echo $this->form->getInput('timecreated'); ?> <div class="control-group"><br><br><br>
<div class="control-label"><?php echo $this->form->getLabel('question1'); ?></div>
<div class="controls"><?php echo $this->form->getInput('question1'); ?></div><br><br>
and in firebug code is :
<div class="controls">
<fieldset id="jform_question1" class="radio" aria-required="true" required="">
<input id="jform_question10" type="radio" aria-required="true" required="" value="Yes" name="jform[question1]">
<label for="jform_question10">Yes</label>
<input id="jform_question11" type="radio" value="No" name="jform[question1]">
<label for="jform_question11">No</label>
<input id="jform_question12" type="radio" value="I am not sure" name="jform[question1]">
<label for="jform_question12">I am not sure</label>
</fieldset>
</div
I want when the user clicks the answer of radio button to check the value and print an alert. But I don't know how to do this in php file. I understand that
<div class="controls"><?php echo $this->form->getInput('question1'); ?></div>
prints the radio values based in an xml file that contains the values but how can I get them and check the value when the user selects it?
If I well understood your query I think that You must use javascript.
If your Joomla version is above 3.0, You can do it with jQuery :
jQuery('#radio_selector').on('click', function(){//verification script});