Forums

Populated Fields and two Submit buttons

gburak 09 Jun, 2009
Could I be directed to any posts that may help with creating the following in Joomla 1.5? (php newbie)

Functionality 1
- user logs in and populates the form fields (text, text area, select, date)
- when clicking 'Save' (the first submit button), the form data is saved to the database and the user receives an email with the form data (I'm successful this far)
- the user is not redirected to a thankyou page but stays on the form page (or is redirected to an identical pre-populated form page)
- after logging out and logging in again, the form would be pre-populated with their data

Functionality 2
- when clicking 'Submit' (the second submit button) the form data is emailed to a different recipient
- the user is redirected to a thankyou page

thanks! (If I can't figure this out on my own, I'm willing to pay a programmer.)
GreyHead 10 Jun, 2009
Hi gburak,

I think that you can reshow the form with the current data by using
<?php
$MyForm->showForm($formname, $posted);
$error_found= true;
?>
in the Onsubmit After box.

To find the data on login you aill need to save the data in a database table with the User id. Then in the form HTML check their Id, retrieve the data and populate the form input values.

Functionality 2 is a simple email set-up plus thank you code html in the OnSubmit box.

Bob
gburak 10 Jun, 2009
Thanks for your help on this. I placed:
<?php
$MyForm->showForm($formname, $posted);
$error_found= true;
?>
in the On Submit After box, and it does indeed reshow the form page but its not populated with the current data.
( I'm not sure if or what I should replace in the above code. My form name is 'passport'. I tried replacements such as '$formname' with 'passport'.

------------------------
I've created a table in the database and the form data with the cf_user_id does indeed write into it. Although I didn't insert and fields or code into the form for the user id. The user has already logged into the site before accessing the form.

In the form HTML, to check the user id and retrieve the data and populate the form input values, I used:

at the top of the HTML form code:
<?php
$user = &JFactory::getUser();
$id = $user->get('id');
?>

for each field:
value="{field_name}"

I tried setting the Profile plugin on, with the Profile page configured to:
Table Name: jos_chronoforms_passport
Target Field Name: cf_user_id
Request parameter name: http://burakdesign.com/dillonU/index.php?option=com_chronocontact&task=send&chronoformname=passport

which gave me a populated field but not the current entry. For some reason my jos_chronoforms_passport table is now listing entries in a different order, not the most recent as first (part of the table is ascending, now the other descending; I had set Target Field Name: cf_id at one try.)

------------------------

For the emails, I have two submit buttons:

<input value="Save" type="submit" id="submit_save" /> is used to send the form data to the user each time they update the form

<input value="Submit" type="submit" id="submit_send" /> is used to send the form data to a different recipient

I don't know what code to use in the On Submit After box so that the second submit button goes to the different recipient. Right now the form data is emailed to whomever I specified in the Email template.

------------------------

I've also inserted the Thankyou message in the On Submit After box and it appears on top of the form after submission. I want it to appear on its own page only after using the id="submit_send" button.


Thanks - I keep trying!!
GreyHead 11 Jun, 2009
Hi gburak,

The value="{field_name}"syntax isn't available in the Form HTML. Try setting "Republish fields if error occured" to "Try to Republish" on the Form General Tab (on the AntiSpam tab in older versions).

You need code in the onSubmit Before box to control the emails depending on which Submit button has been pressed. There's nothing in ChronoForms that will automate this.

Then you will need a second piece of code in the OnSubmit After box to either re-show the form or to show the thank you message.

Bob
Max_admin 15 Jun, 2009
Hi,

in case you want to send the emails at any moment:


$MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);


Cheers
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 15 Jun, 2009
Hi, I've been trying! here's my progress report:

(i) reshow form with the current data (successful):

[onSubmit After]:
<?php
$MyForm->showForm($formname, $posted);
$error_found= true;
?>

[Anti Spam]
Republish fields if wrong submission: Try to republish

(ii) find data on login (partially successful):
save the data in a database table with the User id
- [form HTML]: check their Id, retrieve the data and populate the form input values

I'm successful retrieving data from the jos-users data table with

<?php
$user = &JFactory::getUser();
$id = $user->get('id');
?>

input value="<?= $user->fieldname;?>"

but not successful in setting it up to retrieve data from my jos_chronoforms table. I looked at another post:
'Populating a form from previously submitted data': http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=13061
I didn't know how to set up the mentioned array:
<?php
$db =& JFactory::getDBO();
$query = "
SELECT *
FROM #__chronoforms_ce ";
$db->setQuery($query) WHERE xxxxx;
$rows = $db->loadResultArray(xxxx);
?>
but saw the suggestion to use the Profile Page plugin for this, which I tried but was unsuccessful: I'm sure I'm not setting up the Request parameter correctly. I used:
Table name: jos_chronoforms_passport
Target field name: cf_id
Request parameter: http://burakdesign.com/dillonU/index.php?option=com_chronocontact&Itemid=556&cf_id

(iii) two submit buttons with different emails (successful but not the intended solution):
I couldn't find any posts that may show the code for controlling the emails in the onSubmit Before box. I looked at the post '2 buttons, two different outcomes' http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=14575 (even though it was for exiting to a different url not an email) and was unsuccessful.

I did look at 'Email recipient based on drop-down using FAQ31' http://www.chronoengine.com/forums/index.php?option=com_chronoforums&cont=posts&f=5&t=13060&p=33468&hilit=multiple+emails#p33468 and was successful but this solution is not using the two submit buttons as I had intended.

thanks, I'll keep trying!
Max_admin 16 Jun, 2009
Hi,

for (ii)

I suggest you save all data except passwords in the chronoforms table then use the profile plugin from the latest release to load this data into the form using the "editable" feature, you don't have to go over every field and use php to add a value!

for (iii)

you may check the posted value of the button, then based on this run this line of code:
    $MyFormEmails->sendEmails($MyForm, $MyFormEmails->emails);


the $MyFormEmails->emails is an array of emails objects loaded from the chronoforms emails table, you may use a simple SELECT query to select which emails to be loaded each time!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 17 Jun, 2009
Still not configuring the Profile plugin correctly - I'm not understanding how to use the 'Request parameter name'. I'm appending &id=cf_user_id to the menu link url, and I'm sure its wrong.

I've attached snapshots of the database table and Profile Plugin Configuration.

---
and to confirm: in the HTML code I set the field values to value="{field_name}" ?

thanks!![attachment=0]burak_profile.gif[/attachment]
Max_admin 22 Jun, 2009
Hi gburak,

your request param should be "id" ONLY, assuming you will open your form and append to the URL &id=1 or 2 or whatever!

you don't need to add value="{field_name}" if you will turn on the editable mode!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 22 Jun, 2009
Sorry, now I'm totally confused:
I've set the request param to "id" ( no & sign, no url); yet this confuses me as the table I wish to access only has cf_id and cf_user_id, no columns of just id.

then to append to the URL &id=1 or 2: I can't see in any of the configuration tabs where to do this, and I can't see how I can use a specific id value as this form should be populated by different users with different id values at different times.

ready to give up😟
Max_admin 23 Jun, 2009
you choosed cf_id as the target table field! now your form is ready to pass the value of the "request parameter" to a query to select from the table the value which matches the cf_id

the query works like this:

WHERE "target table field" = "value comes from the request parameter"


so if you set the request parameter to id and you have id=2 in the url then it will be:

WHERE cf_id = 2


then add {date_1} in your form code and make sure the plugin is enabled under the plugins tab, and the form should replace {date_1} by the date field data of record 2

I wish this is more clear!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 24 Jun, 2009
yes thanks Max, this is much clearer now and I'm having almost complete success:

(i) I tried the target set to cf_id with param ID and it was working but not giving me different data for different users, so I played around with the configs

(ii) I tried target set to cf_user_id with param &itemid=523 (which is from the page url when I load the form from the menu item) and it worked as intended: the form is populated with the user's latest data after moving to another page and back, or logging out and back in again.

(actually this seems to work even when I leave the param config empty!? )

(iii) the only problem left is that the select and text area fields don't populate like the text fields do. I'm using value="{field_name}" in the tags which works just for the text fields. If I write {field_name} outside a select or textarea tag it does indeed populate properly. I tried creating a new data table setting the select and textarea column type from VARCHAR(255) to TEXT and other trials but without success.

Is there a way to get these select and textareas to populate too?

thanks for all your patience and assistance!
Max_admin 24 Jun, 2009
Please show me again a screenshot for the profile plugin config and an example URL you access to load the form!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 24 Jun, 2009
To access the form, use:
http://burakdesign.com/dillonU/index.php?option=com_chronocontact&Itemid=523
(login on left side of page with name:author, pass:author)

I've also included in the HTML code:
<?php
$user = &JFactory::getUser();
$id = $user->get('id');
?>
<input value="<?= $user->email; ?>" id="text_1" name="text_1" type="hidden" />

for a dynamic mail to the user every time they update the form. (I'm wondering if this is why the form works without a Request Parameter Name?)

thanks!
Max_admin 25 Jun, 2009
Hi,

you have many fields with cf_user_id = 62 so we can't use this as the table field, so we will keep the test 1 settings and change ID to id then try to access the form with this url :

http://burakdesign.com/dillonU/index.php?option=com_chronocontact&Itemid=523&id=72


let me know!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gburak 25 Jun, 2009
thanks Max, yes this works, again just for the text fields, when I append &id=xx to the URL. I'm not sure however if this is the set-up intended:
-- the user is to login to the site, use the menu item to access the form, and the fields are to be populated with their previous data - not asking each user to themselves append a given &id=xx to a url (unless you have in mind some extra coding so that the different &id=xx are automatically appended the to menu url for different users at login)

-- note: the param id seems to auto change to ID when I go back to the profile plugin congif
-- note: the select and text areas still don't populate with the table table (as before when I used target cf_user_id)

(the target cf_user_id does work for the intended set-up; its just that the select and textareas are not populating.)

thanks!
gburak 25 Jun, 2009
gosh Max I had it working perfectly and then something somehow messed up.
I was using target cf_user_id with an empty parameter
and used
<textarea value="">{field_name}</textarea>
rather than
<textarea value="{description_3}"></textarea>
which populuated the textareas and select boxes.

but when I went to extend the form with new fields, the database table started listing the cf_id in a different order:

originally,it was doing
cf_id = 3
cf_id = 2
cf_id = 1
(with the most recent entries showing at the top of the table)

then it started
cf_id = 3
cf_id = 2
cf_id = 1
cf_id = 4
cf_id = 5
(with the most recent entries at the bottom of the table)

if I could get the table to read as before, all would be working fine again!

thanks!!
gburak 26 Jun, 2009
I got it working again but not consistently. the reordering of the cf_id in the data table had something to do with me deleting rows. At any rate I'm pursuing an unconventional method and I am returning to your advised target cf_id and param id.

As mentioned earlier I need to have this form work without users appending the url themselves: they login, and based on their userid, the form populates with their most recent updated data entry. Are there steps I'm still missing?

thanks again!
Max_admin 26 Jun, 2009
Hi, the coming release will have a more enhanced version!🙂

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
phoe2693 10 Jul, 2009
as a followup, Im wondering how you would go about linking to this created page - with a form and profile plugin - from a menu? I would write code to get the ID that I want to put in a link to the page (mysite.com/blah.php?a=1&id=<?php return getUserId() ?> kind of thing) but how would you put that into a menu, so the form was used when the people logged back in (rather than having to put their ID into the url string as a get variable for us...??????
GreyHead 10 Jul, 2009
Hi phoe2693,

If I understand what you are asking correctly, the best way is to check the user-id in the Form HTML - you can get the Joomla User Object with JFactory::getUser(); that way the url doesn't need to specify the user at all.

Bob
phoe2693 10 Jul, 2009
Yes, I had read that a little earlier... However, it does mean that the Profile plugin wouldnt work at all for this page - allowing easy editing of content. Instead, it would need to be removed and custom php for each variable in the page would need to be written. Im not against doing it this way, but assumed that there was probably an easier one than writing a custom query, detecting previous data, and populating the form if required. It *looked* like the Profile plugin would be ideal, and it is except there dosent appear to be a way to link to it from a menu... which if thats all the problem is a very funny thing all in all, because the form is the work and the menu is simply a short dynamic link...
GreyHead 11 Jul, 2009
Hi phoe2693,

Looking at the Profile Plugin code it should get the current UserID if there is (a) no parameter in the $_REQUEST array and (b) no default value set in the Plugin Configuration.

I haven't tested but I think that if you use a standard menu link and leave the 'Default Request Parameter Value' setting empty then it should pick up the current user.

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

VPS & Email Hosting 20% discount
hostinger