Forums

combining several input fields into one database entry

QueenTut 24 Aug, 2009
Sometimes, to make things easier for the user , I want to break up an entry into a couple of input fields but the administrator needs the information as one database entry.
For example the administrator wants one database entry for Birth_Date but on the form I want to break it up into month/day/year.
Here is the code I used on the form

<div class="cf_item">
  <h3 class="cf_title">Birth Date</h3>
  <div class="cf_fields">
    <table cellspacing="0" cellpadding="0" width="12em" title="" class="multi_container">
        <tbody width="100%">
            <tr width="100%">
                <td style="width: auto; vertical-align: middle; text-align: left;">
<div class="cf_item">
  <h3 class="cf_title" style="width: 30px;">mm</h3>
  <div class="cf_fields">
    <input name="b_date_m" type="text" value="" title="" class="cf_inputtext cf_inputbox validate-number" maxlength="2" size="2" id="text_3" />
    <br />
    <label class="cf_botLabel"></label>
  </div>
</div>
</td>
<td style="width: auto; vertical-align:bottom; text-align: center;">
<div class="cf_item"> <span class="cf_text">/</span> </div>
</td>
<td style="width: auto; vertical-align: middle; text-align: left;">
<div class="cf_item">
  <h3 class="cf_title" style="width: 30px;">dd</h3>
  <div class="cf_fields">
    <input name="b_date_d" type="text" value="" title="" class="cf_inputtext cf_inputbox validate-number" maxlength="2" size="2" id="text_4" />
    <br />
    <label class="cf_botLabel"></label>
  </div>
</div>
</td>
<td style="width: auto; vertical-align:bottom; text-align: center;">
<div class="cf_item"> <span class="cf_text">/</span> </div>
</td>
<td style="width: auto; vertical-align: middle; text-align:center;">
<div class="cf_item">
  <h3 class="cf_title" style="width: 50px;">yyyy</h3>
  <div class="cf_fields">
    <input name="b_date_y" type="text" value="" title="" class="cf_inputtext cf_inputbox validate-number" maxlength="4" size="4" id="text_2" />
    <br />
    <label class="cf_botLabel"></label>
  </div>
</div>
</td>

            </tr>
        </tbody>
    </table>
  </div>
</div>
  <div class="cfclear"> </div>
  <div class="cfclear"> </div>
</div>

<div class="form_item">
  <div class="form_element cf_button">
    <input value="Submit" name="button_1" type="submit" />
  </div>
  <div class="cfclear"> </div>
</div>

I added Birth_Date to the database and I have tried using to the following code in the form code, in the On Submit code or as extra code but I can't get any full entries under Birth_Date in the database table. The best I can do is get the strings //

<?php
$Birth_Date = "$b_date_m" ."/". $_POST["b_date_d"] ."/". $_POST["b_date_y"]
?>
<input value="<?php 
echo $Birth_Date 
?>" id="hidden_0" name="Birth_Date" type="hidden" />

Any advice would be useful.
Thanks in advance.
GreyHead 24 Aug, 2009
Hi QueenTut,

<input> tags only work in the Form HTML. Add a hidden field to the Form HTML
<input type='hidden' name='Birth_Date' />
The set the value in the OnSubmit Before field
<?php
$b_date_d = JRequest::getInt('b_date_d', '', 'post');
$b_date_m = JRequest::getInt('b_date_m', '', 'post');
$b_date_y = JRequest::getInt('b_date_y', '', 'post');
JRequest::setVar('Birth_Date', $b_date_m."/".$b_date_d."/".$b_date_y);
?>

Bob

Later - removed some extra ""s
QueenTut 24 Aug, 2009
Thank-you Bob,
I got rid of an extra pair of quotation marks in the last line. I changed it to:
JRequest::setVar('Birth_Date', $b_date_m."/".$b_date_d."/".$b_date_y)

and it worked perfectly.
Thanks again.
Cheers
DharmaMix 28 Aug, 2009
This is very similar to what we are trying to do, which is attach a datecode (mmyyyy) to the beginning of a user's answer to a question, separated by a "---" to make breaking them back apart easy. It's a very simple form but this has proved surprisingly difficult. The form includes:

textarea name="text_0"
hidden input name="qom_date"
submit button

In ChronoForms, in the "On Submit code - before sending email" code area, I've put:

<?php
$ntext = JRequest::getVar('text_0', '', 'post');
$ndate = JRequest::getVar('qom_date', '', 'post');
JRequest::setVar('text_0', $ndate.' --- '.$ntext);
?>


The text does appear in the database after submitting, but it does not have the date nor the separator. I've been banging my head against this wall long enough now to ask for assistance. Mad thanks for any help!
DharmaMix 28 Aug, 2009
Scrap that last bit... On a hunch, I moved the block of code to the onSubmitAfter and it is working. Any reason why the OnSubmitBefore would not be triggering? BTW, love ChronoForms, we have used them intensively and licensed the site gladly.
GreyHead 28 Aug, 2009
Hi Dharmamix,

OnSubmit Before only works if you have Emails set to On in the General Tab - odd quirk (you don't need to have any emails setup).

Bob
DharmaMix 29 Aug, 2009
Thanks. Yeah, I did a little testing and found that the quirk shows up when trying to save to the database as well. As you said, however, it is only if no emails have been set up and only if "before emails" has been selected. It's easily circumvented once understood, and likely linked.

Best,
~Jaya
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}