错误提示:Notice: Undefined index:cannot set user id_id in D:\phpStudy\WWW\web\index.php on line 4

debug - Notice: Undefined index - WordPress Development Stack Exchange
to customize your list.
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. J it only takes a minute:
Here's how it works:
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Got this great contact us page to use on in my theme. It works great, but the problem is, in debug mode I get undefined index errors on the following line of code:
= $_POST['name'];
= $_POST['email'];
= $_POST['text'];
= $_POST['human'];
$submitted
= $_POST['submitted'];
So I changed the code to the next two pieces of code based on previous answers and tutorials:
= (isset($_POST['name'])
? $_POST['name']
= (isset($_POST['email'])
? $_POST['email']
= (isset($_POST['message'])
? $_POST['message'] : '');
= (isset($_POST['human'])
? $_POST['human'] : '');
$submitted
= (isset($_POST['submitted'])
? $_POST['submitted'] : '');
if (isset ($_POST['name'])) {
$name = $_POST['name'];
if (isset ($_POST['email'])) {
$email = $_POST['email'];
if (isset ($_POST['message'])) {
$message = $_POST['message'];
if (isset ($_POST['human'])) {
$human = $_POST['human'];
if (isset ($_POST['submitted'])) {
$submitted = $_POST['submitted'];
The first set of code removes all debug error messages, but when you submit the form, it triggers the
$missing_content
message which fires when all fields are left empty.
The second set of code gives me undefined index debug error messages on the following set of code:
$headers = 'Van: '. $email . "\r\n" .
'Aantwoord op: ' . $email . "\r\n";
if(!$human == 0){
else if ($submitted) my_contact_form_generate_response("error", $missing_content);
&p&&label for="name"&&?php _e('Naam')?&&span&*&/span&&br&&input type="text" name="message_name" value="&?php echo esc_attr($name); ?&" placeholder="Iemand Anders"&&/label&&/p&
&p&&label for="message_email"&&?php _e('E-pos')?&&span&*&/span&&br&&input type="text" name="message_email" value="&?php echo esc_attr($email); ?&" placeholder=""&&/label&&/p&
&p&&label for="message_text"&&?php _e('Boodskap')?&&span&*&/span&&br&&textarea type="text" name="message_text" placeholder="Skryf asseblief jou boodskap hier."&&?php echo esc_textarea($message); ?&&/textarea&&/label&&/p&
It also gives me the
$missing_content
This all tells me that somehow somewhere I must define name, email, text, human and submitted. And this is where my limited skills halts me.
Any suggestions on how to define the above and to remove the errors and still have the form to work as it should. Before I forget, the complete code can be viewed
39.2k1141102
closed as off-topic by , ♦, ♦
This question appears to be off-topic. The users who voted to close gave this specific reason:&Questions should be specific to WordPress within
(merely happening in its context, such as generic PHP/JS/HTML/CSS, is insufficient). Might be better asked at
or other appropriate site of .& & Chip Bennett, kaiser, toschoIf this question can be reworded to fit the rules in the , please .
Try using the first code - that worked, but gave errors when submitted the form blank and just cahnge isset($_POST['name'] to:
isset($_POST['name'] && !empty($_POST['name']
In your code you are triggering the $missing_content it the vars are empty. According to the spec (see reference) an empty (so not filled as in your case) string will trigger this. Also a string is considered empty if it is not set so in adition to the aforementioned code I would suggest to first set all the values first.
Reference:
Now personaly I would change your code to look something like this (please bare in mind that it's totally late here and I'm after 10 hours of coding so I'll just give you a piece to start):
First set some important for you vars that has to be filled by user and will help you to verify the form. I'll use name, email and text.
$error_name =
$error_email =
$error_message =
I'm setting them to false since on start we assume everything is ok and the user will fill everything. Then we set as well as get the values. Now you didn't post your DOM for the form but I assume your submit button has the submitted name and ID.
if (isset($_POST['submitted'])) {
$name = '';
$email = '';
$message = '';
So after the form is submitted the values are set. Sure they are all empty right now but now at least we will not have issues with values missing and not set. Because of that we can omit later on isset because we are sure they are indeed set. Now let's get some real values so here's the continuation of above code:
if (trim($_POST['name']) === '') {
$error_name =
$name = trim($_POST['name']);
What happens here is we check if the value is set to nothing. And since we did that ourselves at the beginning then if the user didn't input anything we can be sure that there was a field missing. We also use trim so if someone uses only spaces or tabs etc. it will trim those so the value would still be nothing. If so then we set the $error_name to be true. We will use that later. Now if the value is not equal to nothing then we know the user really took the effort to input their name so we assign the value. Of course this is just one part. You would have to do this three times for each value (name, email and message).
Ok we are all set. We have the values the user sent and even if they didn't input anything we at least know we have set them to nothing and we have error vars set to true if such thing happened. Time to use those error vars:
if (!$error_name && !$error_email && !$error_message) {
//rest of your form sending procedure goes here
$contact_form_not_filled =
So in the end we check if all error vars are false. If so we can proceed and send the form if not we set other var to true which we can then use to trigger for example an AJAX message or just a simple notification like so:
&?php if (isset($contact_form_not_filled) && $contact_form_not_filled == true) : ?&
&strong&&?php 'Error! ' ?& &/strong&&?php 'Fill out the form correctly and try again.' ?&
Not the answer you're looking for?
Browse other questions tagged
rev .25629
WordPress is a trademark of the WordPress Foundation, registered in the US and other countries. This site is not affiliated with the WordPress Foundation in any way.
WordPress Development Stack Exchange works best with JavaScript enabled提供主流cms教程
提供数据库教程和设计
提供各种常见网页js代码
提供常用的JS特效代码及在线演示
提供jQuery插件教程及插件下载
提供服务器常见问题及教程
提供站长技术、站长资讯等内容
提供常用开发手册和开发工具
您现在的位置:& >
解决ECSHOP 前后台出现NOTICE: UNDEFINED VARIABLE: DATA IN
导读:今天有一个客户的ecshop网站访问不了,打开他的网站出现一个很少出现的错误提示Notice: Undefined variable: data in ,详细错误提示如...
今天有一个客户的ecshop网站访问不了,打开他的网站出现一个很少出现的错误提示&Notice: Undefined variable: data in &,详细错误提示如下:
Notice: Undefined variable: data in /home/***.com/public_html/includes\lib_base.php on line 1241
Warning: require(/home/***.com/public_html/upload/languages//common.php) [function.require]: failed to open stream: No
such file or directory in home/***.com/public_html/upload\includes\init.php on line 121
Fatal error: require() [function.require]: Failed opening required &/home/***.com/public_html/upload/languages//common.php& (include_path=&.; /home/***.com/public_html/upload/&) in
home\***.com\public_html\upload\includes\init.php on line 121
问题分析:
出现上面Notice: Undefined variable: data in这个问题,我们很容易就想到,是不是用户做过什么特别的修改,或者网站的空间满了。经过了解,都不是。那是什么原因呢,小编在查看文档之后,找到了原因,原来是ecshop 的缓存紊乱。
如何解决:
明白这类问题的原因,我们就知道如何解决了。即然是ecshop缓存的原因,那么我们更新一下缓存就可以了。大家都知道ecshop的网站后台有一个刷新缓存功能,而这里我们网站的后台也进不去,那么怎么更新缓存呢。那如何更新ecshop的缓存,主要有以下两个步骤:
1、& 网站根目录下的temp/static_caches/里面的除了index.html文件的所有文件都删除。
2、 删除 temp/caches/下所有文件夹里面的内容。
转载请注明(B5教程网)原文链接:
网友评论:var sogou_ad_id=731545;
var sogou_ad_height=90;
var sogou_ad_width=980;

我要回帖

更多关于 cannot set user id 的文章

 

随机推荐