SentiJB Posted April 25, 2021 Share Posted April 25, 2021 1. what am i doing wrong this is the form for putting the data in db : <form action="{$VAL_SELF}#aquarium_write" method="post"> <p> <label for="rev_naam_aquarium">Aquarium Naam</label> <input id="rev_naam_aquarium" type="text" name="aquarium[naam_aquarium]" value="{$WRITE.naam_aquarium}" class="textbox required" /> </p> <p> <label for="rev_public">Vink aan indien dit openbaar mag zijn </label> <input type="checkbox" id="rev_public" name="aquarium[public]" value="1" /> </p> <p> <label for="rev_uniek_id">Uniek Aquarium ID</label> <input id="rev_uniek_id" type="text" name="aquarium[uniek_id]" value="{$WRITE.uniek_id}" class="textbox" /> </p> <p> <label for="rev_opmerking_aquarium">Optionele Opmerking bij aquarium</label> <textarea id="rev_opmerking_aquarium" name="aquarium[opmerking_aquarium]" class="textbox required" rows="10" cols="40">{$WRITE.opmerking_aquarium}</textarea> </p> <p> <input type="submit" value="sla op" class="button_submit" /> </p> </form> this is what i put in cubecart class if (isset($_POST['aquarium']) && is_array($_POST['aquarium'])) { $error = false; foreach ($GLOBALS['hooks']->load('class.cubecart.aquarium') as $hook) { include $hook; } $record = array_map('htmlspecialchars', $_POST['aquarium']); $record['customer_id'] = $GLOBALS['user']->get('customer_id'); $record['uniek_id'] = (isset($_POST['uniek_id'])) ? $_POST['uniek_id'] : ''; $record['public'] = (isset($record['public'])) ? 1 : 0; $record['time'] = time(); if (!$error) { if (($id = $GLOBALS['db']->insert('CubeCart_aquarium', $record)) !== false) { foreach ($GLOBALS['hooks']->load('class.cubecart.aquarium.insert') as $hook) { include $hook; } $GLOBALS['gui']->setNotify(gelukt); } else { $GLOBALS['gui']->setError(niet gelukt); } httpredir(currentPage(null)); } else { foreach ($_POST['aquarium'] as $key => $value) { $_POST['aquarium'][$key] = htmlspecialchars($value); } $GLOBALS['smarty']->assign('WRITE', $_POST['aquarium']); } } database : 1 id Primaire sleutel int(10) UNSIGNED AUTO_INCREMENT 2 customer_id int(10) UNSIGNED 3 uniek_id text utf8_unicode_ci 4 time int(10) UNSIGNED 5 naam_aquarium text utf8_unicode_ci 6 opmerking_aquarium text utf8_unicode_ci 7 public tinyint(1) everything gets stored in the database EXCEPT: uniek_id public Searching whats wrong for a while now . What am i doing wrong. 2nd question : how can i generate a random number for field uniek_id can't use session_token , every input has to be different and do i post it to the form like this then ? : <p> <label for="rev_uniek_id">Uniek Aquarium ID</label> <input id="rev_uniek_id" type="text" name="aquarium[uniek_id]" value="{$the_random_token}" class="textbox" /> </p> Link to comment Share on other sites More sharing options...
bsmither Posted April 25, 2021 Share Posted April 25, 2021 Everything POSTed is contained within the $_POST['aquarium'] array, but you are later testing for $_POST['uniek_id']. We see that you sent all of $_POST['aquarium'] through htmlspecialchars and gave the result to $record. Thus, modifying $record['public'] should work. After fixing the statement modifying $record['uniek_id'], that should also work. I see no reason why it doesn't. Also, the setNotify() and setError() arguments need to be either a variable of quoted strings. What you have now are constants (if that is what you really want). CubeCart provides a function to generate a string of randomly chosen letters/numbers A-Za-z0-9: randomString(). It defaults to giving a string of 30 characters. Link to comment Share on other sites More sharing options...
SentiJB Posted April 26, 2021 Author Share Posted April 26, 2021 6 hours ago, bsmither said: CubeCart provides a function to generate a string of randomly chosen letters/numbers A-Za-z0-9: randomString(). It defaults to giving a string of 30 characters. ok thx , will see if it works with only the post things. Will clean up the code also ok this is the function for the string : function randomString($length = 30) { $str = ""; $characters = array_merge(range('A', 'Z'), range('a', 'z'), range('0', '9')); $max = count($characters) - 1; for ($i = 0; $i < $length; $i++) { $rand = mt_rand(0, $max); $str .= $characters[$rand]; } return $str; } how do i get to work that {$str} is filled in <p> <label for="rev_uniek_id">Uniek Aquarium ID</label> <input id="rev_uniek_id" type="text" name="aquarium[uniek_id]" value="{$str}" class="textbox" /> </p> Link to comment Share on other sites More sharing options...
bsmither Posted April 26, 2021 Share Posted April 26, 2021 In the PHP code, you would have: $GLOBALS['smarty']->assign('the_random_token',randomString()); Then, in the template, you now have a value for {$the_random_token}. Link to comment Share on other sites More sharing options...
SentiJB Posted April 26, 2021 Author Share Posted April 26, 2021 thx for the help Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.