Jump to content

Php Problem


Marcti
 Share

Recommended Posts

Hi Guys!My name is marc and i have a problem here. I have this order form that you will be able to see below. my problem is that the number of item is alot. i only put a few to show you the codes i have. i need help on knowing how to use if then statement to skip the items that doesnt have its Quantity filled.example item $MCP6q and $MCP6Aq have some number in it . but the other items doesnt. so what i wan is how to make that when the user submits the form. instead of getting all 500 items , he will just receive the items that have some variables stored.in the email this is what he will getOrdered By: Marc TiEmail : helpme@gmail.comcontact : 3456789message: message goes hereOrder listQuantity: 1200 - Checkbox: yes - Product: MCP-6Quantity: 200 - Checkbox: yes - Product: MCP-6Aas you can see , it skipped the next 2 items which was not filled at the form ,how can do it? help?mail( "emailgoeshere", "form","Ordered by: ".$name." ".$last." \nEmail : ".$email."\nContact : ".$contact."\nCompany : ".$company."\nMessage : ".$message."\n \nOrder list \nQuantity: ".$MCP6q." - Checkbox: ".$MCP6." - Product: MCP-6Quantity: ".$MCP7q." - Checkbox: ".$MCP7. " - Product: MCP-7Quantity: ".$MCP8q." - Checkbox: ".$MCP8." - Product: MCP-8Quantity: ".$MCP6Aq." - Checkbox: ".$MCP6A." - Product: MCP-6A); echo "Thank you. Your message have been successfully sent. Please wait for a reply within 48 hours.";thanks in advance , i hope you guys can help me

Link to comment
Share on other sites

Where are you getting the item/quantity info from? A database or server variables, or...?

Link to comment
Share on other sites

Where are you getting the item/quantity info from? A database or server variables, or...?
from the text box and check box i have on the formi have $MCP6q = $_REQUEST['MCP6q'] ; $MCP7q = $_REQUEST['MCP7q'] ; $MCP8q = $_REQUEST['MCP8q'] ; $MCP6Aq = $_REQUEST['MCP6Aq'] ; etc etc aboveso the answer is variables? i didnt make a database for this.
Link to comment
Share on other sites

Oh, so does the form post to the same page or something?

Link to comment
Share on other sites

Oh, so does the form post to the same page or something?
nope what they will see is the thank you for blah blah blah but the info will be sent to the email. which works but what i need is for the form to send the stuff that have variables in it. cause right now there are around 600 products and every time someone send something all 600 products will be at the mail. so its hard to look for which one was filled up.so if the sender just filled up 10 items /600 then on the email there should only be 10 items not 600
Link to comment
Share on other sites

Okay, well, what happens on form.php? You can use recursion to cycle through the form inputs and only process the ones that are set. For the purposes of creating the email confirmation, that means creating a variable that will hold the output. For example:$display_block="";foreach($_POST as $k=>$v) {$display_block .= "$k = $v";}echo $display_block;That's just a stupid example, but the power of it is apparent. In your case, you have an input with a certain name, then the next input is the same name with a trailing q. If you are sure you can't use a db, then my suggestion (please let the gurus get a chance too, though) would be something like:- foreach $_POST key, check if the last letter is q- if it is, skip it- skip it if it's 'submit', too- if it isn't, then we need to do something with this because it's a product code- concatenate 'q' onto the $key to get the quantity- add whatever info we need to the $display variableSo:

$display = "";foreach($_POST as $key=>$val) {//make sure the form input name doesn't end in 'q'if($key != 'submit' && !preg_match("/^.*q$/",$key) {$display .= "Product code: $key, Quantity: $_POST[$key."q"]";}}echo $display;

I haven't tested that, particularly the regex, but something along those lines should do what's needed. You can tweak the formatting, etc. to be exactly as you like.

Edited by chibineku
Link to comment
Share on other sites

I don't know if it will help at all but you could try this:$MCP6q = isset($_REQUEST['MCP6q'] ) ? $_REQUEST['MCP6q'] : false;$MCP7q = isset($_REQUEST['MCP7q']) ? $_REQUEST['MCP7q'] : false;$MCP8q = isset($_REQUEST['MCP8q']) ? $_REQUEST['MCP8q']: false;$MCP6Aq = isset($_REQUEST['MCP6Aq']) ? $_REQUEST['MCP6Aq'] : false; Assuming that the $_REQUEST's are only set if the field is filled out. If you don't know what this does, here's an explanation:$variable = condition ? valueiftrue : valueiffalseIt checks for the condition (in this case if the specific $_REQUEST is set), and if the condition is true, it sets the variable to the value in the valueiftrue place (in this case, the $_REQUEST itself). If not, it sets it to the valueiffalse value (in this case false).From there, you'll have to build the message. Maybe something like:$message;if($MCP6q != false){$message .= "Quantity: ".$MCP6q." - Checkbox: ".$MCP6." - Product: MCP-6";}And do something like that for each. This is not very dynamic, but it'd work I guess. YOu'll have to tweak the code to your needs, of course. These are just examples. If I were you I'd build a database for the whole thing, give each item an ID and use the ID to query by. If you want it to be more dynamic, I can't really help you unless I see all the code you use.

Link to comment
Share on other sites

//Form----------- $name = $_REQUEST['name'] ; $last = $_REQUEST['last'] ; $email = $_REQUEST['email'] ; $contact = $_REQUEST['contact'] ; $company = $_REQUEST['company'] ; $message = $_REQUEST['message'] ;//quantity---------- $MCP6q = $_REQUEST['MCP6q'] ; $MCP7q = $_REQUEST['MCP7q'] ; $MCP8q = $_REQUEST['MCP8q'] ; $MCP6Aq = $_REQUEST['MCP6Aq'] ; $MCP7Aq= $_REQUEST['MCP7Aq'] ;//checkbox--------- $MCP6 = $_REQUEST['MCP6'] ; $MCP7 = $_REQUEST['MCP7'] ; $MCP8 = $_REQUEST['MCP8'] ; $MCP6A = $_REQUEST['MCP6A'] ; $MCP7A = $_REQUEST['MCP7A'] ;//echo--------------------------------------------------------------- mail( "marccrichelle@yahoo.com", "meiko form","Ordered by: ".$name." ".$last." \nEmail : ".$email."\nContact : ".$contact."\nCompany : ".$company."\nMessage : ".$message."\n \nOrder list \nQuantity: ".$MCP6q." - Checkbox: ".$MCP6." - Product: MCP-6Quantity: ".$MCP7q." - Checkbox: ".$MCP7. " - Product: MCP-7Quantity: ".$MCP8q." - Checkbox: ".$MCP8." - Product: MCP-8Quantity: ".$MCP6Aq." - Checkbox: ".$MCP6A." - Product: MCP-6AQuantity: ".$MCP7Aq." - Checkbox: ".$MCP7A." - Product: MCP-7A);echo "Thank you. Your message have been successfully sent. Please wait for a reply within 48 hours.";so you will have an idea the site is http://meikotools.com.ph/order.htm

Edited by Marc Ti
Link to comment
Share on other sites

Welkommen

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...