Passing a Value from PHP to the SimpleModal Contact Form

懵懂的女人 提交于 2019-12-08 10:39:46

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/3258751/passing-a-value-from-php-to-the-simplemodal-contact-form

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!