I appreciate any help and advice. I have a table settings with 2
fields: value(primaryKey) and setting, value is integer, setting is
string.
value setting
1 reviews
2 columns
3 features
4 categories
I want to switch settings, for example, value 1 will have setting
features, and value 3 will have setting featurs. and no value will
have the same setting. I set a view page change.thtml, so that I can
update setting. I am learning, and very slow. I couldn't firgure out
how to do it. So far I have the following problems:
1. Everytime hit submit, it doesn't save teh change I made. What I
want is to save all the changes I made, it has at least 2 rows or 2
fields. I tried to used saveField, it didn't work also.
2. Another problem is javascript I used to validate that no two
settings have the same value. I don't know how to compare the selected
value since all the select have the same name. You can see all input
have the same name, all select have the same name, as below source
code from firefox:
<tr><td><input name="data[Setting][value]" value="1" disable="true"
type="text" id="SettingValue" /></td><td> <select name="data[Setting]
[setting]" id="SettingSetting">
<option value="" > </option>
<option value="columns" selected="selected">columns</option>
<option value="reviews" >reviews</option>
<option value="videos" >videos</option>
<option value="features" >features</option>
</select></td></tr><tr><td><input name="data[Setting][value]"
value="2" disable="true" type="text" id="SettingValue" /></td><td>
<select name="data[Setting][setting]" id="SettingSetting">
<option value="" > </option>
<option value="columns" >columns</option>
<option value="reviews" selected="selected">reviews</option>
<option value="videos" >videos</option>
<option value="features" >features</option>
</select></td></tr><tr>
********************************************
Here is my code for change.thtml:
*********************************************
<h1>Settings</h1> <a href="javascript: history.back();" style="text-
decoration: none;"><- Back</a><br /><br />
<script language="javascript">
<!--
function checkform ( form1 ) {
var has_same_value = 0;
var msg = "You selectd the same value in these sections:";
if (form1.select1.selectedIndex == form1.select2.selectedIndex) {
msg += "\n position 1 and position 2";
has_same_value = 1;
}
if (form1.select1.selectedIndex == form1.select3.selectedIndex) {
msg += "\n position 1 and position 3";
has_same_value = 1;
}
if (form1.select1.selectedIndex == form1.select4.selectedIndex) {
msg += "\n position 1 and position 4";
has_same_value = 1;
}
if (form1.select2.selectedIndex == form1.select3.selectedIndex) {
msg += "\n position 2 and position 3";
has_same_value = 1;
}
if (form1.select3.selectedIndex == form1.select4.selectedIndex) {
msg += "\n position 1 and position 4";
has_same_value = 1;
}
if (missing = 1) {
alert(msg);
return false;
}
else {
alert(msg);
return true;
}
}
</script>
<pre>
<?php //print_r($menu); ?>
</pre>
<form name = "form1" method="post" onSubmit ="checkform(form1)"
action="<?php echo $html->url('/settings/change')?>">
<table>
<tr>
<th>Position</th>
<th>Sections</th>
</tr>
<!-- Here's where we loop through our $settings array, printing out
setting info -->
<?php
for($i=0; $i < $count; $i=$i+1){
echo '<tr><td>';
//echo $html->input('Setting/value', array('value' =>
$settings[$j]
['Setting']['value']));
echo $html->input('Setting/value', array('value' =>
$settings[$i]
['Setting']['value'], 'disable' => 'true'));
echo '</td><td> ';
$default = $settings[$i]['Setting']['setting'];
echo $html->selectTag('Setting/setting', $menu,
$default); //Does
this set default value?
echo '</td></tr>';
}
?>
</table>
<p><?php echo $html->submit('Change') ?></p>
</form>
************************************************************************
here is my function change() in settings_controler.php
**************************************************************
function change(){
$data = $this->Setting->findAll();
$this ->set('settings',$data);
$count = $this->Setting->findCount();
$this->set('count', $count);
$menu = $this->Setting->generateList(null, "value ASC", null,
'{n}.Setting.setting',"{n}.Setting.setting");
$this->set('menu', $menu);
if (!empty($this->data))
{ foreach($this->data as $data){
$this->Setting->create();
$this->Setting->save($data);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---