Jump to content

Recommended Posts

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 by ixnayz
Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/
Share on other sites

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;
			}
		}
	}
?>
Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489106
Share on other sites

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?
Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489108
Share on other sites

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();
Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489109
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489114
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489116
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489118
Share on other sites

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). 

Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489140
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/290692-js-and-php/#findComment-1489221
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.