views:

41

answers:

1

What is the simplest way to pass a value from the "index" page to the SimpleModal Demo Contact Form? For example, if a user is logged in and their email address is stored in the variable $email, what is the most straightforward way to have that info available in the Demo Contact Form?

Thank you.

A: 

Assuming the values you want are NOT in the form, here's a way to do it.

Update contact.js in the onShow: function:

...
}, function () {
    $('#contact-container .contact-loading').fadeIn(200, function () {

        var pt = PAGE_TITLE,
            aid = ARTILE_ID;

        $.ajax({
            url: 'data/contact.php',
            data: $('#contact-container form').serialize() + '&action=send&page_title=' + pt + '&article_id=' + aid,
            type: 'post',
            cache: false,
            dataType: 'html',
            success: function (data) {
                $('#contact-container .contact-loading').fadeOut(200, function () {
                    $('#contact-container .contact-title').html('Thank you!');
                    msg.html(data).fadeIn(200);
                });
            },
            error: contact.error
        });
    });
});
...

Then update contact.php in the function smcf_send() function

...
// Set and wordwrap message body
$pt = isset($_POST["page_title"]) ? $_POST["page_title"] : "";
$aid = isset($_POST["article_id"]) ? $_POST["article_id"] : "";

$body = "From: $name\n\n";
$body .= "Page Title: $pt\n";
$body .= "Article ID: $aid\n\n";
$body .= "Message: $message";
$body = wordwrap($body, 70);
...

Obviously you can play around with the details, but that should get you going.

-Eric

Eric Martin
Thanks a million, will definitely get me going.
RandallK
For anyone else who might come along and try this, there is a small typo in the first code. There is a + missing before aid (took me awhile to figure out why it wouldn't work!) But aside from that, it works awesome! Thanks again for making this great code available, and supporting it so quickly.
RandallK
Sorry about the typo; it is fixed now.
Eric Martin