ixnayz Posted August 27, 2014 Share Posted August 27, 2014 (edited) Hello, I,m doing an internship and they've asked me to do a 'sales page' where you pick a product and its features through diferent listboxes in a HTML page, the idea would be after clicking 'Send' to send an email to the sales department with the product and the options chosen to study the order. So far I have everything donde except the send email function where I'm getting the same error 'undefined index' and I can't see the values stored. iDesk.innerHTML= '<b>Product</b> - ' + zProduct + '<br><b>Bay</b> - ' + zBay + '<b... This is js file, I intend to pass the values of zProduct, zBay in the php file so I can send them as a list by email. $message .= "Product - " . $_POST["zProduct"] . "<br>"; This gives me the same error 'undefined index zProduct', I've asked around and someone told me to try to store the values from the javascript file with $.post( "send.php", { zProduct: zProduct, zBay: zBay...}) but I'm still getting the same error, can someone help me out? Thanks. Edited August 27, 2014 by ixnayz Quote Link to comment Share on other sites More sharing options...
requinix Posted August 27, 2014 Share Posted August 27, 2014 Can you post the whole thing instead of just a couple lines? Quote Link to comment Share on other sites More sharing options...
ixnayz Posted August 27, 2014 Author Share Posted August 27, 2014 The Js file is too big so I'm posting the part dealing with php, this is what a friend told me to try: function div_show(){ document.getElementById('abc').style.display = "block"; document.getElementById('formtable').hidden=true; document.getElementById('DivDesc').hidden=true; document.getElementById('DivSend').hidden=true; document.getElementById('DivSum').hidden=true; <?php $.post( "send.php", { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} ); ?> } this gives me the undefined index error, and this is the php file: <?php if(isset($_POST["vSubmit"])){ if($_POST["vName"]==""||$_POST["vEmail"]==""||$_POST["vSub"]==""||$_POST["vMsg"]==""){ echo "Fill All Fields.."; } else{ $email=$_POST["vEmail"]; $email =filter_var($email, FILTER_SANITIZE_EMAIL); $email= filter_var($email, FILTER_VALIDATE_EMAIL); if (!$email){ echo "Invalid Sender's Email"; } else{ $subject = $_POST["vSub"]; $message = $_POST["vMsg"] . "<br>" . "<br>" . "Specs" . "<br>" . "<br>" . "Hola" . "<br>"; $message .= "Product - " . $_POST["zProduct"] . "<br>"; /* $message .= 'Bay -' . $_POST['zBay'] . "<br>"; $message .= 'Measures -' . $_POST['zMeasures'] . "<br>"; $message .= 'Door -' . $_POST['zDoor'] . "<br>"; $message .= 'Plinth -' . $_POST['zPlinth'] . "<br>"; $message .= 'Mount -' . $_POST['zMount'] . "<br>"; $message .= 'Battery -' . $_POST['zBattery'] . "<br>"; /* $headers = 'From:'. $vEmail . "<br>"; $headers .= 'Cc:'. $vEmail . "<br>"; $message = wordwrap($message, 70); mail("xxxx@gmail.com", $subject, $message, $headers); echo $message; } } } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted August 27, 2014 Share Posted August 27, 2014 What's the code you have now? Because apparently it's sending vSubmit and vName and other vThings and the new code doesn't have those. { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery}Where are all those values being defined? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 27, 2014 Share Posted August 27, 2014 Where are these values coming from? $.post( "send.php", { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} ); Also, if you are using jQuery, why are you doing this stuff? document.getElementById('abc').style.display = "block"; document.getElementById('formtable').hidden=true; document.getElementById('DivDesc').hidden=true; document.getElementById('DivSend').hidden=true; document.getElementById('DivSum').hidden=true; When you could just $('#abc').css('display', 'block'); $('#formtable, #DivDesc, #DivSend, #DivSend').hide(); Quote Link to comment Share on other sites More sharing options...
CroNiX Posted August 28, 2014 Share Posted August 28, 2014 Another thing, why are there php tags wrapping your jquery $.post()? Quote Link to comment Share on other sites More sharing options...
ixnayz Posted August 28, 2014 Author Share Posted August 28, 2014 Wow, many responses, let me answer one by one. requinix: the vName, vEmail and the rest are from the form I'm sending, I removed the part dealing with them by mistake and since they seemed to work fine while controlling the no empty field thing, I just forgot about them. { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} There's a zProduct and the rest at the js file, my friend told me that doing this would also create the variables in the php file as well. Right now the js file doesn't have that line since it seems to be doing nothing at all, plus I'm having the same error while only using the php file as it is. CroNiX: $.post( "send.php", { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} ); This values are the ones I use to store the options selected, and this friend told me that this line in the js file would pass the variables and their contents to the php file. I have been using jQuery for a really short time and the code is still half-jq half old-js until I am more confident with it, sorry for the confusing read. The same happens with php, I'm still learning and things get confusing when mixing different languages. So, any solution to my problem? How would you pass the values from the js file to the php file so I can send them? Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted August 28, 2014 Share Posted August 28, 2014 One problem is, none of the values you are passing along with your post are being set. $.post( "send.php", { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} ); Where is zProduct, zMeasures, zDoor etc etc being set? Another issue, you have that same line wrapped in php tags. It's not php. Quote Link to comment Share on other sites More sharing options...
ixnayz Posted August 28, 2014 Author Share Posted August 28, 2014 One problem is, none of the values you are passing along with your post are being set. $.post( "send.php", { zProduct: zProduct, zBay: zBay, zMeasures: zMeasures, zDoor: zDoor, zPlinth: zPlinth, zMount: zMount, zBattery: zBattery} ); Where is zProduct, zMeasures, zDoor etc etc being set? Another issue, you have that same line wrapped in php tags. It's not php. These values exist in the js file, and I thought that the line would create them in the php file as well. If I define them first in the php file would it work? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted August 28, 2014 Share Posted August 28, 2014 I think you are confusing PHP and javascript as the same language. PHP and Javascript are completely different languages. They are both ran a completely different times. This is because PHP is a server side language, meaning it is ran on the server. The PHP code is parsed when a request for a .php file is made to the server. Any other code such as HTML/CSS/Javascript used within the PHP code will be ignored. Languages such as HTML/CSS/Javascript are client side, meaning they are parsed by the the web browser client (eg Internet Explorer, Firefox, Chrome etc). The browser parses the HTML/CSS/Javascript that is returned by the the server (eg the output from a PHP script). Quote Link to comment Share on other sites More sharing options...
ixnayz Posted August 28, 2014 Author Share Posted August 28, 2014 I think you are confusing PHP and javascript as the same language. PHP and Javascript are completely different languages. They are both ran a completely different times. This is because PHP is a server side language, meaning it is ran on the server. The PHP code is parsed when a request for a .php file is made to the server. Any other code such as HTML/CSS/Javascript used within the PHP code will be ignored. Languages such as HTML/CSS/Javascript are client side, meaning they are parsed by the the web browser client (eg Internet Explorer, Firefox, Chrome etc). The browser parses the HTML/CSS/Javascript that is returned by the the server (eg the output from a PHP script). I understand the part of each being executed from different sides, so how would you do it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.