How to use same input value in multiple DB fields?

clochard 30 Aug, 2009
Greetings,

Question:
How can I use the same input value/variable to store in multiple DB fields?


I've tried to use {valueid}, but it only works for the email report.
In the DB, it stores exactly that : {valueid} ; instead of its real value, lets say "stuffenteredbytheuser".

Context
I'm trying to build a form to create categories.
User submits text, and this should be used for the db fields : title, name, alias.
All input is of type="hidden", except the text input, "title".

Form Code (HTML tab)

<!-- The first one is the one I want to reuse-->
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 150px;">Date du Voyons voir</label>
    <input class="cf_inputbox required" maxlength="150" size="30" title="title" id="title" name="title" type="text" />  
  </div>
  <div class="cfclear"> </div>
</div>
<!-- One of the two fields where I want to reuse. OK in Email but not in DB -->
<input value="{title}" id="name" name="name" type="hidden" />
<!-- One of the two fields where I want to reuse. OK in Email but not in DB
The rest is the hidden stuff -->
<input value="{title}" id="alias" name="alias" type="hidden" />
<input value="16" id="section" name="section" type="hidden" />
<input value="left" id="image_position" name="image_position" type="hidden" />
<input value="" id="description" name="description" type="hidden" />
<input value="1" id="published" name="published" type="hidden" />
<input value="0" id="checked_out" name="checked_out" type="hidden" />
<input value="0000-00-00 00:00:00" id="checked_out_time" name="checked_out_time" type="hidden" />
<input value="" id="editor" name="editor" type="hidden" />
<input value="" id="ordering" name="ordering" type="hidden" />
<input value="0" id="access" name="access" type="hidden" />
<input value="0" id="count" name="count" type="hidden" />
<input value="imagefolders=*2*" id="params" name="params" type="hidden" />
<div class="form_item">
  <div class="form_element cf_button">
    <input value="OK" name="button_21" type="submit" />
</div>
</div>
clochard 31 Aug, 2009
Sorry for posting before trying $everything.

Problem solved using the OnSubmit Events Code, which I put before the Autogenerated block in the RunOrder Tab.
Code used is simply php handling the _POST data.

BUT : Was there ready-built pseudo-code that I could have used instead?

Thanks,
Hugo.
GreyHead 31 Aug, 2009
Hi clochard,

It depends. If you use the Joomla 'bind + store' code (as ChronoForms does - see the Autogenerated Code for an example ) then any fields in the $_POST array with matching names in table columns will be saved to the db. Otherwise you will need to write and execute a MySQL query.

Both systems will work, both are useful in different circumstances. As you found the {field_name} syntax does not work here. But there are many many examples of the Joomla JRequest::getVar() syntax in these forums. ChronoForms also puts the results into a $posted array but - off the top of my head - I'm not certain where that is available.

Bob
clochard 31 Aug, 2009
Salut Greyhead,
you *are* up to your reputation of rocket-fast reply. Thanks.

I'm much more a designer than a coder, so I still have this question.
Hope you don't mind answering it even if it is a newbie one.

Now my form is for registered users. Menu item is set for that, and I've added a redirect on top of Form Code for not-logged-in users.
Even then, is my Onsubmit code (wich directly handles the $_POST[] variables) weaker/less safe than going for the JRequest::getVar() ?

Best regards.
GreyHead 31 Aug, 2009
Hi clochard,

If it's well written and you are validating, then probably not. The advantage of the Joomla code is that it does have some built in filtering (unless you deliberately over-ride it) and lets you easily add some type validation with getInt, getString, etc.

Bob
This topic is locked and no more replies can be posted.