DIV 内的 PHP 联系表单设置为“显示:默认情况下无”时出现问题

发布于 2024-12-11 05:01:52 字数 361 浏览 0 评论 0原文

我们正在使用 PHP 为使用 GetSimple 3.0 CMS 的画廊网站构建产品页面。我们正在尝试创建一个在您单击按钮时显示的联系表单。默认情况下,联系表单位于设置为显示:无的 DIV 中。当您单击该按钮时,它会显示:block。当用户单击表单的提交按钮并调用该操作时,它会加载 contact.php 文件并将 DIV 重置为显示:none,导致用户看不到其表单已提交的确认文本。您只能通过再次单击联系人按钮并显示要手动阻止的 DIV 来查看它。

我们希望联系表单 DIV 在单击提交按钮后保留。我不认为展示我们的代码会有帮助。如果可能的话,我们只是想找到一种方法来实现这个想法。

目前我们的网站仍处于早期开发阶段,并且仍在本地托管。

感谢您的任何帮助。

We're using PHP to build a product page for a gallery website that's using GetSimple 3.0 CMS. We are trying to create a contact form that is displayed when you click a button. By default the contact form is in a DIV that's set to display: none. When you click the button it displays: block. When a user clicks the submit button for the form and calls the action it loads the contact.php file and resets the DIV to display: none resulting in the user not seeing the conformation text that their form was submitted. You can only see it by clicking on the contact button again and displaying that DIV to block manually.

We'd like the contact form DIV to persist after the submit button is clicked. I don't think showing our code would be helpful. We're just trying to find a way to implement this idea if possible.

At present our website is still early in it's development stage and it's still being hosted locally.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

对你的占有欲 2024-12-18 05:01:52

使用该特定表单的ajax提交,这样即使页面不会刷新,焦点也不会丢失

use ajax submission of that particular form so that focus will not loss even the page will not be refreshed

三月梨花 2024-12-18 05:01:52

如果您可以编辑用于构建页面的 PHP 代码,则始终可以根据请求动态显示样式,如下所示:

<div style="display:<?php echo (isset($_REQUEST['answer'])) ? 'block' : 'none';?>>
    Thank you!
</div>
<form action="contact.php" method="post">
    <input type="hidden" name="answer" />
     ...
</form>

您还可以提交表单而无需重新加载页面,例如使用 JQuery.Forms

If you can edit PHP code used for building the page, you can always display the style dynamically depending on the request, like this:

<div style="display:<?php echo (isset($_REQUEST['answer'])) ? 'block' : 'none';?>>
    Thank you!
</div>
<form action="contact.php" method="post">
    <input type="hidden" name="answer" />
     ...
</form>

You can also submit a form without reloading the page, e.g. with JQuery.Forms

离不开的别离 2024-12-18 05:01:52

如果表单和 PHP 文件都位于 Contact.php 中,您可以考虑使用此方法:

<div id="formWarp" <? if($_POST["contact"] == "true"){ echo 'style="display:none" '; } ?>>
   <form method="POST" action="Contact.php">
     <input type="text" name="something"/>
     <input type="hidden" name="contact" value="true"/>
   </form>

您可以包含任何其他 在表单内。

If both the form and the PHP file are located in Contact.php, you could consider using this:

<div id="formWarp" <? if($_POST["contact"] == "true"){ echo 'style="display:none" '; } ?>>
   <form method="POST" action="Contact.php">
     <input type="text" name="something"/>
     <input type="hidden" name="contact" value="true"/>
   </form>

You can include any other <input>'s inside the form.

风吹过旳痕迹 2024-12-18 05:01:52

编辑:完全更改以反映为更直接地解决问题而获得的新信息。

阅读您的上述评论,我相当有信心我们正在寻找要编辑的错误函数。您发布的函数中不存在包装器元素,而该函数需要切换其显示。

一旦您找到该代码块,我们就可以对其进行编辑以查找是否存在发布数据,这表明页面正在表单提交后加载(我不能保证这不会导致它在如果此页面上有多个表单,则为错误时间)并写入样式属性以覆盖默认值(如果测试为真)。

在该插件中的某些地方会有一些定义表单包装元素的内容

$html = '<div id="some-unique-id" class="some-class-name">';

您可以分解此行并测试发布数据添加内联样式属性(如果找到)

$html = '<div id="some-unique-id" class="some-class-name"'; //tag left open

if(isset($_POST) && (count($_POST))){ //Some Post Data Exists
  $html .= ' style="display:block;"'; //Add display overwrite
}//Some Post Data Exists

$html .= '>'; //close the tag

我们在这里执行的测试是 if(isset($_POST ) & (count($_POST))){ 正在检查以确保 A) $_POST 存在并且 B) 它至少有一个元素(这是使用类型杂耍以转换数字将 count() 的结果转换为其布尔等价值(其中任何大于 0 的值都将测试 true

现在,正如我所提到的,可能有更多此页面上不止一个表单,之后可能会显示它,当您不想显示您的联系表单时,根据您在评论中提供的示例,该功能似乎存在于一个中。如果我们正在寻找的代码块可能存在于同一个类中。可以利用id属性来限制检查以从您感兴趣的表单发布数据。

$html = '<div id="some-unique-id" class="some-class-name"';

//Check for contact form specific post data 
//(if $this->id is within scope and still the same)
if(isset($_POST) && (isset($_POST['p01-contact' . $this->id]))){
  $html .= ' style="display:block;"'; //Add display overwrite
}//Post Data Exists

$html .= '>';

在此测试中,我们希望 $this 存在,并且 $this 的属性 id 与表单创建时的属性 id 相同。最初绘制的是这样我们可以查找与特定联系表单相关的帖子数据。 (我们正在寻找的名称基于您作为评论发布的代码示例)

不幸的是,如果不查看网站/插件的源代码,我将无法告诉您在哪里可以找到您正在寻找的东西。一旦找到它,这两种情况之一应该有望解决您的问题。

这是我们可以查看的公开可用插件还是内部开发的插件?

EDIT: Completely changed to reflect new information obtained to more directly address the problem.

Reading your above comments I'm fairly confident we are looking at the wrong function to edit. The wrapper element is not present in the function you posted which is what needs to have it's display toggled.

once you find that block of code we can edit it to look for the presence of post data which would indicate that the page is being loaded after a form submission has occurred (I can't promise that this won't cause it to trigger at the wrong time if there is more than one form on this page) and write in a style attribute to overwrite the default value if tested true.

Some where in that plugin there will be something defining the forms wrapper element

$html = '<div id="some-unique-id" class="some-class-name">';

You can break up this line and put a test for post data adding an inline style attribute if found

$html = '<div id="some-unique-id" class="some-class-name"'; //tag left open

if(isset($_POST) && (count($_POST))){ //Some Post Data Exists
  $html .= ' style="display:block;"'; //Add display overwrite
}//Some Post Data Exists

$html .= '>'; //close the tag

The test we are performing here is if(isset($_POST) && (count($_POST))){ which is checking to make sure that A) $_POST exists and B) it has at least one element (this is using type juggling to convert a numeric result from count() into its Boolean equivalent (where anything greater than 0 will test true)

Now, as i mentioned, there may be more than one form on this page and it is possible it will be displayed afterwards which would auto show your contact form when you don't want to have it showing. Based on the example you provided in a comment it looks like this function exists within a class. If the block of code we are looking for exists within the same class it might be possible to leverage the id attribute to restrict the check to post data from the form you are interested.

$html = '<div id="some-unique-id" class="some-class-name"';

//Check for contact form specific post data 
//(if $this->id is within scope and still the same)
if(isset($_POST) && (isset($_POST['p01-contact' . $this->id]))){
  $html .= ' style="display:block;"'; //Add display overwrite
}//Post Data Exists

$html .= '>';

In this test we are hoping that $this exists and the attribute id of $this is the same as it was at the time that the form was originally drawn so we can look for post data that is related to the specific contact form. (the name we are looking for is based off of the code example you posted as a comment)

Unfortunately without looking at the source of the site/plugin it will be impossible for me to tell you where you can find what you are looking for. Once you find it though one of these two scenarios should hopefully take care of your problem.

Is this a publicly available plugin we could look at or something developed in-house?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文