We have a very large form and we are posting the data to mysql using $_POST, but we have 2 complex sections in the form where we need your help.
HTML markup of form
<label>Customer Name</label>
<input type="text" size="50" name="name" />
<label>Education</label>
<input type="text" size="50" name="class" />
<input type="text" size="50" name="board" />
<input type="text" size="50" name="subjects" />
<input type="text" size="50" name="aggregate" />
<label>Payment Plan</label>
<ul id="fields"></ul>
We are appending following to #fields using jquery
<li><input type="text" size="30" name="date" /> <input type="text" size="30" name="amount" /> </li>
Now we would like your help with the following problems...
How to post education details to mysql table? - using php serialise?
how to post appended input boxes to mysql's tbl.paymentplan?
If you've populated the fields using jquery (date & amount) and it's on the form, a simple "Submit" button which posts to a PHP page that handles the insert into the database should work fine.
Nothing complex about it. I use jquery to pre-load form data all the time like that.
If you want to avoid doing a postback entirely, and want to do that through jquery as well, you can. Once the data is loaded into the DOM and the form displays it you can do with it what you want.
Algorithm
use mysql_fetch_field to know all attributes name from your table
if attribute does not exist in current table then update table via php like below
mysql_query("ALTER TABLE paymentplan
ADD date CHAR(30) AFTER subject,
Add payment CHAR(30) AFTER date");
and then insert the data the way u want.
Reference
mysql fetch field
Related
Kind of an odd question and kinda hard to explain so will try my best.
I am wondering if it is possible to take the following:
<label for="page_name">page name</label><br>
<input type="text" name="page_name" maxlength="50" size="30">
and Display none; in the CSS so that this field isn't visible to anyone filling our the form, so that its left blank. Well not blank I would like to have a preset value so that when the form is filled out, I get all their entered details and I get my preset field "page_name" that has text I have entered so that I can put for example "page 5" so that I can see which page the form has been filled out on.
Is it possible to do it in html? I have done in the past by making each page have its own form and this time around I feel like there must be an easier solution?
Thanks in advance!
Simple use type="hidden" value="your value"
<input type="text" type="hidden" value="your value" name="page_name" maxlength="50" size="30">
and submit this input field with other all fields
This is very possible, I used it to track IP adresses once.
You can simply set the value by hand:
<input type="text" name="page_name" value="Default input value" style="display:none;">
Make sure you set it to display:none; (this can be done from your stylesheet too).
Set the value="default value" wich is what otherwise would be entered by the user.
Example:
function showvalue(){
alert($('input').attr('value'));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="page_name" value="Default input value" style="display:none;">
<button onclick="showvalue()">Show value </button>
With a HTML form, can I rely on the ordering of the fields in HTML be the same as the data beingsent to the server?
For example if I have 2 inputs:
<input type="text" name="one"/>
<input type="text" class="aaa" name="two[]"/>
<input type="text" class="bbb" name="two[]"/>
When parsing the data on the server side and looping over input named 'two', can I rely on the fact that input.aaa will be first in the loop.
I am using php, but the same question applies to all major backend languages receiving form (post) data.
No.
You can manipulate the order by manually setting the index in the input's name:
<input type="text" class="aaa" name="two[0]"/>
<input type="text" class="bbb" name="two[1]"/>
I have a form which is super simple.
<input type="text" name="tel">
So basically user hits submit and save new record with only the Tel.
what i want is to allow the user to create many tel row in the database. I have found a few different way of doing this and would like to know which approach is the best.
1) is to duplicate my form and increment the number which means i would need to write a lot of code.
<input type="text" name="tel">
<input type="text" name="tel1">
<input type="text" name="tel2">
<input type="text" name="tel3">
submit would create 4 new rows but this method would create allot of coding for its intended purpose.
2) I found a few references to using a class but i haven't got the slightest idea where to start with classes.
is there a simpler way of achieving this or is option 1 my best bet?
Use it like this.
<input type="text" name="tel[]">
<input type="text" name="tel[]">
<input type="text" name="tel[]">
<input type="text" name="tel[]">
and on server side you can extract them as array.
foreach($_POST['tel'] as $tel=>$value)
{
echo $tel.' - '.$value;
}
i am trying to build a meta search engine.
I currently have the following code.
<form method="POST" action="google_basic.php">
<label for="service_op">Service Operation</label><br/>
<input name="service_op" type="radio" value="Web" CHECKED />
Web <input name="service_op" type="radio" value="Image" />
Image <br/> <label for="query">Query</label><br/>
<input name="query" type="text" size="60" maxlength="60"
value="" /><br /><br /> <input name="bt_search" type="submit"
value="Search" /> </form> <h2>Results</h1>
{RESULTS}
I need the form to have more than one action= ""(I realise a form can only have one action, i need the equivalent of 3 actions ="" ). The form needs to access 3 search engines and display the results. What is the best way to do this?? I know that javascript may an option but is not a solution for me as it may be switched off in the clients browser.
Any ideas on the best way to go about this??
TIA
You need to perform the 3 "actions" on the server (in or from the google_basic.php file). After POSTing to the server, you can perform an arbitrary number of "actions" from there.
See also: http://us2.php.net/manual/en/intro.curl.php
it only needs one action, then the action is what will display all 3 searches. so instead of having google_search.php, bing_search.php, and yahoo_search.php, combine them all into a generic search page that will display all 3
I have this:
echo '<input type="text" id="address" name="address" value="'.$address.'" />';
When you enter your adress (my+adress) in search form and hit button "Search" I want to search automatically add cityname and country in link, to link look like .../index.php?address=my+adress+citiname+county.
Thanks in advance!
So just use a method="get" in the post field and it will dump the fields to the URL?
<form action="" method="get">
<input type="text" name="myAddress">
<input type="text" name="city">
<input type="text" name="county">
<input type="submit" value="Go Search">
</form>
If you don't want to add in the fields, you will need to parse the myAddress field and use a meta redirect to populate the data you parsed from their address.
It would be much more straightforward to either:
add cityname and country in index.php, if those are known in _SESSION
or:
add a (possibly hidden) field in the form with cityname and address, even if you will receive two different values from your form and require merging them
To do exactly what you want, you need to modify the query just before it is submitted; it is easiest to do this, e.g., using jQuery.