I need to store value from input field in form one. Reason why I need that is when I send form 2 in the same file, all filled input fields in form 1 is blank. My thinking is to read value from form 1 and in form 2 make hidden field with that value. When I send form 2, I can $_POST that hidden field as value in form 1. Now I use jquery:
<script type="text/javascript">
$('#search_field').val('<?=$value?>');
var = $('#search_field').val();
</script>
All works if I in that field echo $_GET value. In some cases I need that, but if $_GET is no set, I need to fill that field by myself. How can I store value what I filled by myself?
First form is search form, what sends data to search engine.
Second form is calendar fields, what specifies time for search results. I have 3 choises - all, 30 days, 10 days. When I click 10 days, then calendar fills out automatic.
<form>bla bla 1</form>
<form>bla bla 2</form>
No, problem. Depending on what you need.
And if you really have to "submit" data without submitting a form you have to use AJAX/Javascript (OR use a normal link [=GET] for that).
Related
I don't need any code, I just need the right way to do it.
What I am doing?
Here is the thing. I am making a software for a pharmacy (Drug Store). I have created a tab for shortlist for the drug. See the picture.
enter image description here
What problem I am facing?
In the last column, I have a form field to input drug or add stock. But you can see there are many form fields for so many rows. When I click to "Confirm" button, it's not gonna work cause the table has been generated using loop. So, for all the fields there are same name.
How can I take the value of input field right above the submit button. I mean when I click confirm button it will take same row's input field not others.
How can I do it? No code needed. I am using php codeigniter framework.
Thanks
create one variable like '$i' and increase it and append it on last of input name.as well as give id to submit button and append id with $i.
for eg. name_1,name_2,submit_2,submit_2
when you submit just get the id of submit button. Then get the number from id eg.2,3.take input from the same input variable id. You can do it using ajax. So it will be done without refresh page.
In this question, I found out how to dynamically add form fields.
Now, how can I set a cookie to remember the amount of form fields that were generated, and their content?
eg. First visit, user types this:
Input one
Input two
Input three
Then he/she visits the page again. There are 3 form fields, containg Input one, Input two and Input 3.
Is this possible using a server/client side solution?
Thanks a lot,
Harley
assuming that the input textfield class is "textfield1" -
This snippet will capture the data into a cookie when the value is modified
$(".textfield1").change(function() {
$.cookie("textfield1", $(".textfield1").val(), {expires: 7});
});
This snippet will read the cookie data and populate the field on page load -
$(".textfield1").val( $.cookie("textfield1") );
Put both these snippets inside $(document).ready(function(){ }); and you are good to go !
there is a useful plugin of jquery "Jquery Populate" you can store your json in cookie/session and use it to fill your forms.
How do I pass information from my form plus some additional data when submitted the form. For
example if I am using PHP
I have a form and I set the method to GET; now all the fields in the form will be sent in the URL, now suppose if I want to keep a track of how many times the submit is clicked, for that if I pass the variable count along with all the data through URL, how do I do that?
How do I append this data to the existing form's data?
OR suppose if I have a field in my form where I allow to user to enter name of their employs; initially it will show 4 fields for the data, but if I click the submit type button that says MORE, then it will display 4 more fields, and similarly if again he presses more it shows 12,
so I was thinking maybe I could sent a variable $count along with the form data through URL, but I don't know how to do it.
I would user a hidden field with the "count" value. It will then be passed with all the other form input variables but won't actually be visible to the user on in the form:
<input name="field_name" type="hidden" value="cout_value_that_changes" />
You can change - Field_name - to what ever you want it to be and the value should be incremented every time the submit button is pressed - incremented with PHP -
something like:
$count++;
value="<?php echo $count;?>"
Best solution for your requirement seems Use of JQuery.
Add your fields dynamically using JQuery.
For ref. you may check : http://docs.jquery.com/Main_Page
Without using JQuery, you can have Hidden field which would contain count of the field.
we have to pass count in GET request and while showing field in php, check count field.
If I have a form with the following 3 fields:
First Name Last Name Date Of Birth
When the user fills in all 3 fields and submits you will get the URL
http: //fakeURL.php?firstName=Fred&lastName=Flintstone&DateOfBirth=2/5/1952
However, if the user only fills in First Name and Date Of Birth you will get
http: //fakeURL.php?firstName=Fred&lastName=&DateOfBirth=2/5/1952 (where lastName has no value)
How do I achieve
http: //fakeURL.php?firstName=Fred&DateOfBirth=2/5/1952 (where lastName and value are removed from the URL)
I don't want to disable the input field upon using onsubmit. Is there a better way than disabled the input field?
Please help...
Just remove the "name" attribute from the input element.
// using jQuery
$('#inputId').removeAttr('name');
// native Javascript
document.getElementById('inputId').removeAttribute('name');
You must either:
Remove or disable the field from the form before submitting it
Don't submit the form, instead redirect to a URL you construct from the form yourself
Make an AJAX request instead of leaving the page
Aside from those options, you can't submit this form via GET without all the inputs becoming part of the URL. That's part of the HTML and HTTP specifications.
if you are working on angular and using (ngModel), Remove the name attribute in the input field and add
[ngModelOptions]="{standalone: true}"
You should use forms with the GET method only when the new page is supposed to be bookmarked and passed around.
Since you are talking about you taking input from the user (and I presume you also store that input in a database or some similar permanent storage), you should be using POST instead.
Hello I have a select element which has a few options. I am able to get the selected option when an onChange event is fired. Now I need to pass that option text to php, either with pageload or ajax.
echo $form->select('data_source_select',$dataSourceOptions,null,array('escape'=>false, 'empty'=>'Select One','onChange'=>'getData(this)'));
is my select form element, with its options being set in controller. Now onchange, I need to pass the selected option to php/action to load the data specific to this option search. Any help would be great.
Thanks.
As you said, you could either do this as a regular form submission, or as an Ajax form submission. My answer will focus on regular form submission, since Ajax will essentially work the same way and can simply be added on to enhance it later.
One quick solution is to add a hidden field to your form, maybe call it "step" and give it a value of 1. When the data source is selected, simply submit the form and check the value of "step" in your controller. If it is equal to 1, you'll know to load the data based on data_source_select. If the value of "step" is not 1, it indicates that you're on another step in the process and you don't need to process the data source value again.