I have a html form with multiple input fields, a name and an address for a customer. when the user submits the form the values in these fields are sent into a database made up of 2 tables.
I also have a drop down box with the options ‘yes, and ‘no’. when the form is submitted with ‘no’ selected I need the values to get sent to the database as normal but then instead of clearing the input fields for a new entry I need name and last name to grey out / become read only and keep the values that the user entered in them. while the address fields reset for a new entry.
The user can then enter new values in the address fields and press submit again where these will get added to the address table of my database with the customer Id of the name/lastname they previously entered.
this will be repeated until they press a different button on the form that then sends the final address and resets the entire form for a new customer entry.
So far I have it setup so a user can enter the customer name and address and press submit, it will then get send to the database and the form will reset for another customer entry.
This is my form, with 4 entry fields,
<form name="add" method="post" action="newCustomer.php">
<div id="leftcol">
<label><span>Name</span><br /> <input type="text" name="addFname" /></label>
<label><span>Surname</span> <input type="text" name="addLname" /> </label>
<label><span>Single Site?</span><Select name="field" onchange="showHide(this.value)
</label>
<div id="rightcol">
<label><span>Address line 1</span><input type="text" name="addSiteLine1" /></label>
<label><span>Address line 2</span><input type="text" name="addSiteLine2" /></label>
So far i have tried to add this to the bottom of my php code
if($dropdown== "no"){
disable_text(true);
}
disable text is a javascript function that disables the text, but this didn’t do anything.
I also tried to call this function upon form submit but then that stopped my $_POST methods from obtaining the values. when I set tried this again using read-only instead of disabled nothing seemed to happen.
I am basically trying to avoid needing a second form / webpage for adding customer addresses and trying to avoid adding multiple input boxes for multiple addresses ( because some may have 100+ addresses)
EDIT
$Dropdown is defined in the php as:
$dropdown = $_POST['field'];
in the form as
<label><span>Single Site?</span><Select name="field" onchange="showHide(this.value);">
</label>
<Option value="yes">yes</option>
<Option value="no">no</option>
the function was being called, when the function disabled all of the text fields I could see it happen, they would flash grey then the page would refresh and I would get error messages saying that
$fName = $_POST['addFname'];
could not be defined. when I changed the function to make the fields readonly nothing seemed to happen, it would just submit the data and clear the form ready for a new input.
I may not understand the question so correct me if I am wrong. Can’t you just disable the fields with javascript and save the field values in session variables to carry back to the form?
Make a session variable flag and if that is set on page load then refill the form and disable the fields.