close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Populating a form field from a recordset

Thread began 9/17/2009 1:32 pm by troyd | Last modified 9/19/2009 11:40 pm by troyd | 3311 views | 6 replies |

troyd

Populating a form field from a recordset

I have my completed form and I have added a "Subject" text field. Easy enough as it is, it all works including formatting it with UEmail to dynamically add the subject entered into the email that submits the form. Great.

Now over to my DA record list. I currently have a link that appears in each record. It's an email link that when clicked opens the email and fills in the record ID and Name into the subject of the email. But we are doing away with the pop up email and replacing it with this new secure form.

How do I bind the "Subject" field in the FB form with the record ID they click on and still maintain validation for that field?
AND ignore that binding if someone simply goes to the contact form and puts in whatever they want into the Subject field?

So far, I can get the Subject field to populate using a link from the record. But it removes the "invalid" value currently in the field for validation.

Can this even be done? I have all extensions.

Thanks,
TroyD

Sign in to reply to this post

anonymous

Troy,

If I understand you right, you have a page that has records that someone could click a "contact" link and then you would have Universal Email grab the data from that row and input it to your email.

But now, you are going to have them click your link and now go to the form so they can use a form to fill out the info. And furthermore, you want a particular field from the database to populate the subject field in that form?

If that is right, you could do it one of two ways. If you just need the subject, you can have your link carry the data in the URL. So in your table your a href address for your link would be something like "contact_form.php?subject=$_row['subject']".

And then on contact_form, you would then first check to see if the URL variable exists (at the top of your page)... if it does, you then set the value into another variable like this:

if ($_GET['subject']) {
$formsubject = "$_GET['subject']) ;
} else {
$formsubject = "" :
}

Notice, I used an else statement to set the variable equal to nothing if the URL variable didn't exist... then in your form, you can just set the initial value as <?php echo $formsubject; ?>.

The other way to do it would be to pass the ID through the URL method as described above and then query for a recordset using the WHERE clause to get the fields you need.

Cheers,

Brian

Sign in to reply to this post

troyd

Brian,
Ok, this is very helpful. And thanks in advance. You are correct in your assumption of what I am trying to accomplish.

However I am a little confused on a couple of things. When you say to use contact_form.php?subject=$_row['subject'] for the link, do I actually use that exactly including the subject=$_row['subject'] or do I replace subject with the column I am trying to pass to the url? I know my contact.php page name will be different.

  And then on contact_form, you would then first check to see if the URL variable exists (at the top of your page)...  


And when you say to use the if else statement at the top of the page, where exactly? Or do you mean the url at the top of the browser is where this statement will be looking? I'm sure it's super obvious, but I'm not catching it.

  if ($_GET['subject']) {
$formsubject = "$_GET['subject']) ;
} else {
$formsubject = "" :
}  




What I had tried, was using contact.php?id=<?php echo(rawurlencode($row_rsProduct['id'])); ?> in the a href and that worked to pass the record's ID to the url. And then binding the subject field to the column in the record set that I wanted. But that wasn't working as well and I somehow messed up my validation.

Your way looks like what I really need, I just don't understand it yet. Hope you don't mind a little more explanation.

Thanks,
TroyD

Sign in to reply to this post

anonymous

Hi Troy,

I just used "subject" as an arbitrary marker... it will be whatever column you are trying pass that you will need to put in there.

As far as I can see, your using an ID which I will guess is a number... if it is a number, you won't need to encode it as an ID number won't have any spaces or special characters.

By putting the if statement at the top, I just mean place it in your PHP BEFORE the HTML so it can then set the variable correctly when your form is added to the page.

I also made a mistake in the "if" statement... I accidentally put a colon instead of a semicolon after the else statement... just make sure you use a semicolon instead.

One more thing, if you have a column that actually contains a subject or name, you could pass that instead of ID through the URL and that way you'll actually have the name rather than just an ID number.

Let me know if you need any more help,

Brian

Sign in to reply to this post

troyd

Brian,

Thanks again for the help.
After changing the colon to a semicolon I was still getting an error. So I pulled out my PHP books and started studying. I'm not sure, but I ended up getting it to work by removing the " that was in front of the $_Get on the second line. Please let me know if I should have done something different.

With your help though, I learned that this piece of code is a "Logical Oporator". Is that correct? It basically says that "if" this "whatever" excisists, do this thing. Or "else" do this other thing. In this case it was a generic value variable that would be = to "whatever" was being passed to the contact.php page. If there was no "whatever", then just go on and let the form function as normal.

THEN, in the form field "Subject", I put that reference at the end of the current validation value that FB had already inserted. It works great. Thanks.

One other question. I would like to pass more than one detail to that if statement. For example, ['productname'] and ['productnumber']. Right now, I just added a second echo to the href and it worked. I put a space between them to get a space to appear in the form. But it seems that it could be done a lot cleaner. How would you do it?

For reference, here is what I have so far.

On my contact.php page, as my link in the repeating tables I have;

php:
<a href="contact.php?subject=<?php echo(urlencode($row_rsProducts['productname'])); ?> 

<?php echo(urlencode($row_rsProducts['productnumber'])); ?> ">
Inquire about this product</a>




On the Product List Page;

Your if else statement at the top of the page.

php:
<?php

if ($_GET['subject']) {
$formsubject $_GET['subject'] ;
} else {
$formsubject "" ;

?>



And then your field value; (which is after the validation)

php:
<?php echo $formsubject?>




So that value for my "Subject" field, including the FB validation looks like this;

php:
value="<?php echo((isset($_GET["invalid"])?ValidatedField("contact","fieldset_group_Subject"):"")); ?>

<?php 
echo $formsubject?>"



If you don't mind, please let me know if this looks correct. I know it works because,... well it worked. But I also want to learn proper code so if you see anything I did wrong I would appreciate knowing. Thanks again for your help it was just what I was looking for.

Thanks,
TroyD

Sign in to reply to this post

anonymous

Troy,

That code all looks correct... if you want to pass the product ID too, you can do it the way you are doing it (although I would take the space out as spaces are not standard for html) or define a second variable in the URL.

If you chose to define a second variable, you could do it with the "&" sign...

so your link would like this, now:

<a href="contact.php?subject=<?php echo(urlencode($row_rsProducts['productname'])); ?>&id=<?php echo(urlencode($row_rsProducts['productnumber'])); ?> "> 
Inquire about this product</a>



You could concatenate the two and add a label to the product ID in the subject field like this:

 <?php 
if ($_GET['subject']) {
$formsubject = $_GET['subject'].' - Product ID number:'.
$_GET['id'] ;
} else {
$formsubject = "" ;
}
?>



Now the subject will look this:

Subject: Your Subject - Product ID number: 35

Sign in to reply to this post

troyd

Thanks again Brian,

That worked wonderfully.

TroyD

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...