2

ve tried this a million ways, So i figured i would just break down and ask

typically, my setup is a handler with different events for edit view, and save for form submit

function edit(event, rc, prc) {

        rc.query=getmodel("somemodel").getlist(rc.unique);
        }   

    function save(event, rc, prc){
     event.norender();
     getPlugin("MessageBox").info("#rc.allocation# Saved");
     setNextEvent(event="myhandler.edit", url="edit?unique=#rc.allocation#");
    }

on the edit view, url like this myhandler/edit?unique=99 , i have a form that sets the event of save like this

<form  action="#event.buildLink('myhandler.save">

which essentially creates the link to the save event

Now unless i set a hidden input in my form like this

<input id="unique" name="unique" type="hidden" value="#rc.unique#"/> 

I always get an Error "Element UNIQUE is undefined in RC"

I know there has got to be a way to be able to pass a parameter on form submit without it being defined as an input, i just cannot find a single example on how todo so

Jay Rizzi
  • 4,196
  • 5
  • 42
  • 71
  • Unless you add it to query string of the URL, or define it as a form field, there is no way to pass the parameter on form submit. You could store it in session scope, but then you need a process for clearing it out when it is not needed any longer. Passing values like that as hidden form fields is pretty standard practice. – Scott Stroz Jul 25 '13 at 21:14
  • Really? It wouldnt seem like it would be standard, as anyone with firebug/chrometools could change the input value at will, but i suppose that's what server-side validation is for...least i dont feel so bad about always doing hidden inputs anymore – Jay Rizzi Jul 25 '13 at 21:17
  • If there is, it is a technique that is not known to me. :D – Scott Stroz Jul 25 '13 at 21:20
  • Hacking is something that you always have to be aware of. Passing variables via hidden fields or as query string variables is how every web application language passes variables from client side to server side. There are techniques to manage transient variables other than this, but as Ben has mentioned already it involves session variables, cookies or client variables. It looks like you are using ColdBox, so you might want to look into ColdBox's flash memory. (I think that's what it's called) – Stephen Moretti Jul 25 '13 at 21:29
  • Ok, i appreciate the insight, someone make an answer and I'll accept it – Jay Rizzi Jul 26 '13 at 18:12

1 Answers1

1

You can use event.getValue() to retrieve a value instead of checking RC directly. This allows you to return a default value if it doesn't exist in RC:

<input id="unique" name="unique" type="hidden" value="#event.getValue("unique","defaultValue")#"/> 
Scott Coldwell
  • 868
  • 7
  • 14
  • And you can always do a StructKeyExists(rc, "unique") to do any branching in case you want to alter the behavior based on whether it's there. – jinglesthula Apr 15 '14 at 20:50