How to Set fields as Readonly - php

I have added two fields [ Start_date and End_Date] in Project , can able to update and save values in the fields.
I want to allow fields editable when EDIT button clicked otherwise it should be readonly.
Code changes but doesn't works
<label for="txtstartdate"><?php echo __("Start Date")?> <span class="required">*</span></label>
<input id="txtstartdate" name="txtstartdate" type="text" class="formInputText" disabled="disabled" value="<?php echo $project->getstartDate()?>" disabled />
<br class="clear"/>
function disableWidgets(){
$('#addProject_start_date').attr('disabled','disabled');
$('#addProject_end_date').attr('disabled','disabled');
}
function enableWidgets(){
$('#addProject_start_date').removeAttr('disabled');
$('#addProject_end_date').removeAttr('disabled');
}
In which file i have to change . Any one could help me to achieve this?

Related

inservt database value into date form field

I've created a form so I can update a database table. Everything's working (text, file, select, radio) except my date form fields.
Empty, they show the default date placeholder text: mm/dd/yyyy. I can insert a value manually:
<input name="iu_received" type="date" class="form-control" id="iu_received" value="2022-09-20">
And that will show as 09/20/2022 on the page.
However, trying to insert a value from my database recordset doesn't do anything and the placeholder text still displays. For example:
<label class="form-label mb-0">Date Distributed:</label> <input type="date" class="form-control" name="iu_distrib" value="<?php echo $rsAppl->getColumnVal("iu_distrib"); ?>">
(Yes, the "iu_distrib" value is a mysql date: 2022-09-20.)
How can I make this work?

Magento Telphone filed in Customer_Account_Edit page

I want to do the same as this guy do
Magento: How to display customer's phone number on customer information field
but I don't want only to display the customer phone number, I want to give ability to change the telephone number on this page.
If I follow the guy's above solution I only get the Telephone display in a field but when I submit the form everything else is being saved except this telephone field. What could be the code solution to save the new information after FormSubmission?
Thanks in advance
UPDATE #1
I update /app/design/frontend/base/default/template/customer/form/edit.phtml with this code
<input type="text" placeholder="<?php echo $this->__('Telephone') ?>" name="telephone" value="<?php echo $this->getCustomer()->getPrimaryBillingAddress()->getTelephone() ?>" title="<?php echo $this->__('Telephone') ?>" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone') ?>" id="telephone" />
but it doesn't save (form omit changes) if I change the input value and submit the form.
I wonder why..

Overwrite input value in form field

I have an "Update Profile" script that retrieves the details of the logged in user in a form input, so they can see what the current values are. Like this:
<input type="text" name="first_name" id="first_name" value='<?= $row->f_name; ?>' title="enter your first name.">
This works. When users navigate to the page they see their first name appear in that input box. When they go to change their name and enter in a new value the form submits but keeps the original value and not the updated one. I assume that is because I am hard-coding a value to it with the value attribute.
How can I show the user the value in the input so that if they choose to not edit it, it does submit with the original value and not a blank, but if they do choose to add text to the input box the new string is submitted?
If I understand you correctly:
value="<?=set_value('first_name', $first_name)?>"
The first parameter is the posted value, the second parameter is the default overridden value.
You may want to use placeholder attributes.
<input type="text" name="first_name" placeholder="<?= $row->f_name; ?>">
`if($_GET['first_name']==''){
$first_name= $row->f_name;
}else{
$first_name= $_GET['first_name'];
}`
SQL Query :
"UPDATEyour_table_nameSETfirst_name= '$first_name' WHEREblablabla= '$blablalba';"
&ltinput type="text" name="first_name" id="first_name" value='f_name; ?>' title="enter your first name.">

How do I change the country select into an input field in magento one step checkout?

In the billing_fields.phtml there is
<?php
$billingFields['country_id'] = '
<div class="input-box input-country'.((in_array('country', $formErrors)) ? ' input-error' : '').'">
<label for="billing:country_id">'.$this->__('Country').' <span class="required">*</span></label><br />
'.$this->getCountryHtmlSelect('billing').'
</div>';
?>
I do have only one country and the select-tag $this->getCountryHtmlSelect('billing') with the rendered dropdown is not user friendly as it has no further options. I feel its misleading and obsolete. My question is:
How do I have to change the code above to show my default country in a simple (not editable) input field?
EDIT
I came up with this after CBroes getCountryCollection hint
<?php
$countryCollection = $this->getCountryCollection();
foreach($countryCollection as $country) {
$country_id = $country['country_id'];
$countryName = Mage::getModel('directory/country')->load($country_id)->getName();
$billingFields['country_id'] = '
<div class="input-box input-country'.((in_array('country', $formErrors)) ? ' input-error' : '').'">
<label for="billing:country_id">'.$this->__('Country').' </label><br />
<input type="text" name="billing[country_id]" id="billing:country_id" class="input-text" value="'.$countryName.'" style="width: 83%" readonly="readonly" />
</div>';
}
?>
The frontend looks fine. Even the backend recognizes the given value. Unfortunately the emails don't. The country field remains empty there.
What am I missing or how do I make this input legit so that magento-emails accept its value?

In a bit of a while loop mess!

I have spent quite some time making a function and the last 15-20 minutes trying to figure this out. I need help!
I am selecting multiple rows from the database and then running them in a while loop.
They are available on a dropdown menu.
<form method="POST" action="adminprocess.php">
<fieldset>
<p>
<label class="left2">League:</label>
<select name="league" class="combo">
<?php
$q = $database->selectAllLeagues();
while($row=mysql_fetch_assoc($q))
{
$theid = $row['id'];
extract($row);
?>
<option value="<? echo $theid; ?>">
<? echo $format.'_'.$game.'_'.$name.'_Season '.$season;?>
</option>
<?
}
?>
</select>
</p>
<p>
<input type="hidden" name="replaceleague" />
<input type="hidden" name="format" value="<? echo $format; ?>" />
<input type="hidden" name="game" value="<? echo $game; ?>" />
<input type="hidden" name="name" value="<? echo $name; ?>" />
<input type="hidden" name="season" value="<? echo $season; ?>" />
<input type='submit' class="button" value='Select league' />
</p>
</fieldset>
</form>
$theid seems to be working fine dependning on which row i select on the dropdown menu.
However, I cant get the values below in the hidden inputs to pass through the correct values from the row selected in the dropdown box.
It seems to always pass through the 4 variables from the first row of the database.
So basically, I need it to select the right row and use that data.
What am i doing wrong!!!
Thanks for reading!
Your hidden fields are initialized outside the loop, so they'll use the values that were left over from the last iteration of the while loop. (i.e. the last fetched row)
Why do you actually need the hidden fields in the first place? When you submit the form, the league field will contain the ID of the row selected in the drop-down box. Using the ID, you can fetch the other fields from the database when processing the form.
To directly answer your question about the while loop, it's because the hidden inputs are echoed outside the loop, after which data the last-iterated row from your database is used by PHP to output to those hidden inputs.
But I suggest that instead of using hidden form elements like that, you submit your form with the <option> with the value a user chooses, read the value (as in $_POST['league']), and fetch the row from your database with that ID and use it accordingly. (You may wish to keep the replaceleague hidden input if your application needs it of course.)
It's much easier, plus it ensures the information about the row a user chooses is coming from your database and not tampered with. In fact, for most applications this is the right way to go.

Categories