submission form::passing $id to success template
15 posts
• Page 1 of 1
hi Steve
Situation: Submission form for an events table --> success page (contains a link with an id which is needed for the next submission form) I tried the following in the first form's after new trigger: ------------------snip---------------------- /** * Trigger that is called after new records are inserted. We will use it to * forward to the correct page. */ function after_action_new(){ $app =& Dataface_Application::getInstance(); $record =& $app->getRecord(); $id= $record->val('id'); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ( !$user ){ // The user is not logged in so we forward to a success page. header('Location: success.php?&-id=$id'); exit; } } ------------------------snap----------------------- but ...no luck! Fatal error: Call to a member function val() on a non-object in ......etc. what am I doing wrong? cheers martin
OK.. probably it is objecting to: $record =& $app->getRecord(); To do what you want to do, I think you'll need to implement 2 triggers.Ê One afterInsert() trigger to capture the id of the newly inserted record.Ê And one after_action_new trigger that is more orÊ less like the one you implemented, except that you will use a global variable to pass information between them. e.g. function afterInsert(&$record){ ÊÊÊ globalÊ $inserted_record; ÊÊÊ $inserted_record =& $record; } Then in your after_action_new trigger, change: $record =& $app->getRecord(); $id= $record->val('id'); to global $inserted_record; $id = $inserted_record->val('id'); Also do a check to make sure $inserted_record is not null... -Steve
thanks Steve..
the first part works when i do this: ------------------------------- function afterInsert(&$record){ global $inserted_record; $inserted_record =& $record; $id = $inserted_record->val('id'); echo $id; } ----------------------------------- the correct id is echo'ed. but nevertheless the error still exists fatal error: Call to a member function val() on a non-object in /data/my_url/jos_events.php on line 82 --------------------------------------------------------------------------------------------------------- /** * Trigger that is called after new records are inserted. We will use it to * forward to the correct page. */ function after_action_new(){ $app =& Dataface_Application::getInstance(); global $inserted_record; $id = $inserted_record->val('id'); ----------------^-------------------------------------------------------------------line82-------------- $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ( !$user ){ // The user is not logged in so we forward to a success page. header('Location: success.php?&-id=$id'); exit; } } shame on me , that I bother you on a Sunday martin
Hi Martin, Interesting.Ê For some reason it isn't picking up the global variable $inserted_record. A more explicit way of using global variables is via the $_GLOBALS array. e.g. $_GLOBALS['inserted_record'] =& $record;ÊÊ // In afterInsert() then $id = $_GLOBALS['inserted_record']->val('id');Ê // in after_action_new -SteveÊÊ
hi steve
for the delay in answering.. even the bullet proof $_GLOBALS method did not work... the Error is still the same. maybe it's too much triggering for this delegate class, there' is also an before save trigger in it. -----------whole thing-------------- class tables_jos_events { function getPermissions(&$record){ $app =& Dataface_Application::getInstance(); $query =& $app->getQuery(); if ( $query['-action'] == 'new'/* and (!$record || !$record->val('registrantid'))*/ ){ return Dataface_PermissionsTool::ALL(); } else { $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ( $user and isAdmin($user->val('role'))){ return Dataface_PermissionsTool::ALL(); } else { return Dataface_PermissionsTool::NO_ACCESS(); } } } function block__before_new_record_form(){ echo << Trage Deine Laufsportveranstaltung in unsere Datenbank einFŸlle nach Mšglichkeit alle untenstehenden Felder aus Falls Du bereits bestehende Laufveranstaltungen aktualisieren mšchtest, sende uns bitte eine e-mail mit den geŠnderten Daten. END; } function block__custom_stylesheets(){ echo << END; } /** * Trigger that is called before new records are inserted. We will use it to * get latitude longitude values from the google maps api. */ function field__full_address(&$record){ return $record->strval('adresse_info').'+'.$record->strval('contact_info'); } function beforeSave(&$record){ $auth =& Dataface_AuthenticationTool::getInstance(); $key='ABQIAAAAooZ_SZteboYmTOL4jxD62BSOvuGUx-vwd1f9BNBwMyfFwZh75RRNqIYghOSJherZZaxKd-Rvj_PH1Q'; $nonvalid_adr = $record->val('full_address'); $seach = array(" ", "."); $replace = array("+", "+"); $valid_adr = str_replace($seach, $replace, $nonvalid_adr); $url ="http://maps.google.com/maps/geo?q=".urlencode($valid_adr)."&key=$key&output=csv"; $geo = file_get_contents($url,'r'); $geo_array = explode(',',$geo); $lat = $geo_array[2]; $lng = $geo_array[3]; $record->setValue('content', 'lat='.$lat.'&lng='.$lng); } function afterInsert(&$record){ $_GLOBALS['inserted_record'] =& $record; $inserted_record =& $record; $id = $inserted_record->val('id'); echo $id; } /** * Trigger that is called after new records are inserted. We will use it to * forward to the correct page. */ function after_action_new(){ $app =& Dataface_Application::getInstance(); //global $inserted_record; $_GLOBALS['inserted_record']; $id = $_GLOBALS['inserted_record']->val('id'); $auth =& Dataface_AuthenticationTool::getInstance(); $user =& $auth->getLoggedInUser(); if ( !$user ){ // The user is not logged in so we forward to a success page. header('Location: success.php?&-id=$id'); exit; } } } ------------------------------------ greetings ..with sugar and fancy toppings martin
Ok.. this is where some standard troubleshooting can come in handy.Ê We want to know why the inserted_record variable is getting lost. Possible reasons: 1. Since the $record was copied to the $inserted_record variable by reference, it is possible the original variable could have been mucked with after the fact. ÊÊÊÊÊÊ Try just storing the id in a global variable and see if you can access that. ÊÊÊÊÊÊ Try passing the record by value (i.e. no ampersand). 2. Somewhere else in the program a global variable by the same name is used (unlikely but possible). ÊÊÊÊÊ Steps to test: ÊÊÊÊÊ Try changing the name of the inserted_record variable to something more obscure. .... there are more possibilities, but these were the first to come to mind. -Steve
hi Steve
back from holidays and internet cafe hopping, i tried some of your tips for debugging this morning: first of all i managed to pass the variable to the last trigger by using $GLOBALS instead of $_GLOBALS. and then ...after a while... after I understood that echoing variables and the function header() don't like each other too much, everything worked. thanks for your help cheers martin
I tried
{$smarty.get.id} as decribed here: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=5377&highlight=%24GET in the smarty forum to retrieve the id from the query string ..did not work.. is there an easier way to retieve the $_GET variable I already tried {php}$_GET['id']{/php},that didn't work either do you have an idea? cheers martin
{$smarty.get.id} should have worked. Double check to make sure that id is actually being passed as a GET variable (and not e.g. a POST variable). Alternatively, Dataface adds the following possible methods to get a GET variable in the template: {$ENV.QUERY.id} {$ENV.REQUEST.id} -Steve
hi steve
Even though I am not a PHP Champion, retrieving variables from the query string seemed to be a trivial task to me ... till this day! Here is what I tried so far: 1. in the registration successful.html my first attempt was {$smarty.get.id} ----------------------------------------------------------- {use_macro file="Dataface_Main_Template.html"} {fill_slot name="main_section"} Deine Laufsportveranstaltung wurde erfolgreich in unsere Datenbank übernommenVielen Dank daß Du Dir die Mühe gemacht hast... wenn Du deinen Lauf in eine Google karte eintragen möchtest kannst du das hier tun . zurück zu link. {/fill_slot} {/use_macro} ------------------------------------------------------------- the important part of the above snippet is: i tried the same with:{$ENV.QUERY.id} and {$ENV.REQUEST.id} either with "&-" or without or only with an ampersand without the minus. new approach.... 2. then I tried do read the query string via javascript: I placed this snippet in the Dataface_Main_Template.html the query string looks like this: http://www.my-url.de/dataface-0.7.2/forms/input_event/success.php?id=1959 -------------------------------------------------------------- -------------------------------------------------------------- which alerts the id correctly ! but all my efforts to pass ev_id to the link in the registration_successful.html failed. 3. then I tried to get this javascript working directly in the registration_sucessful.html and outputting the link via javascript, via document.write() , to be able to pass the variable , but i couldn't get the javascript to be executed. so.. more or less desperate i have to ask again for help I am already humming in front of my screen "got to get that $_GET but what I've got ain't worth Dollars yet"! I think it is better for the world when I forego becomming a musician .. cheers martin ps: Do I maybe have to explicitely declare that I want to send the Variable via GET? If so, how do I do this?
oops ..
this postig became completely mixed up , because the javascripts have been filtered out , the snippet without the javascript tags looks like this: ---------------------------------- fullURL = parent.document.URL ev_id = fullURL.substring(fullURL.indexOf('?')+4, fullURL.length) alert('id: '+ev_id); ---------------------------------
Strange ... Some debugging to see what is going on.Ê Try looping through the get vars to see what is there: {foreach from=$smarty.get item=val key=key} {$key} : {$val} {/foreach}
debuging results:
-action : registration_successful the querystring says: http://my-url/dataface-0.7.2/forms/input_event/success.php?id=1961 ??
Hi Martin, Sorry.. just clued in that you are copying the example in the tutorial.Ê The reason that the id is not being picked up is because you are using a rewrite rule to rewrite the url. The rule: RewriteRule success.php admin.php?-action=registration_successful [L] Is says to change all requests for success.php to be admin.php?-action=registration_successful. However it doesn't pass along any of the GET parameters. That rewrite rule is just put in there as an example of how to make "nice" urls.Ê However it will work just as well to just forward the user directly to the admin.php?-action=registration_successful url, and forego the rewrite rule altogether. e.g. instead of using the url success.php?id=12345 useÊ admin.php?-action=registration_successful&id=12345 -Steve
15 posts
• Page 1 of 1
Who is onlineUsers browsing this forum: No registered users and 25 guests |