jwk811 Posted October 2, 2006 Share Posted October 2, 2006 Yeah, and how would I do that. Say if someone has a list of things in a form and each of them will go to a different page if chosen. How can I do that? Something with the if...else... elseif statment? Some code would be great, thanks. Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 While 'some code would be great', a good start would be for you to be rather more specific about what you actually want to happen - examples are great for explanations. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 someone will get a form...there will be a few selections, each which go to another page...like <select><option>Choose this to go to page 1</option><option>Choose this to go to page 2</option></select>Along with the submit.. how will i make this work? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 Something here - http://javascriptkit.com/script/cutindex16.shtml - will do what you want. Quote Link to comment Share on other sites More sharing options...
marknt Posted October 2, 2006 Share Posted October 2, 2006 Try something like this:[code]<form action="<?=$link?>" method="post">[/code]Where the link can be the file itself (" $_SERVER['PHP_SELF'] ") or something like ./edit.php depending on the situation.[quote]Note: A form can only contain [b]ONE[/b] action.[/quote]Furthermore, Sir AndyB is correct. What exactly do you want to happen? ??? Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 like could i to the if..elseif thing to do this.. say i send the form data to a script and in the script it says if they chose "this" then redirect to... with the "Location: url" .. would you know how i could find out which thing was chosen by the user in the next page? would i do the $_POST thing and... well how would i know if something was chosen.. if its "true"?and what did you mean marknt with the link thing? how would that work? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 I assume that the link to all sorts of different javascript redirection scripts isn't what you want. So, you want 'something' different .... with ifs, elses, and if then elses ...Does the script that is receiving the form information do [i]anything[/i] with it other than decide to go to www.wombats_are_us.com if 'wombats' is selected from a dropdown and go to www.cnn.com if 'news' is selected. As I said, a rational description of what [i]you want[/i] will get us where we want to be faster than if we guess ;) Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 thanks for your help, i found what i needed from another threadthe form will be something like this[code]<form action="reffer.php" method="POST"><input type="radio" name="page" value="1">Page 1<br><input type="radio" name="page" value="2">Page 2<br><input type="radio" name="page" value="3">Page 3<br></form>code]and the reffer.php script will be this[code]<?phpif(isset($_POST['page'])){switch($_POST['page']){case 1:header("Location: page1.php");break;case 2:header("Location: page2.php");break;case 3:header("Location: page3.php");break;}}?>[/code]this was exactly what i needed, did you know about this?[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 [quote author=jwk811 link=topic=110189.msg444973#msg444973 date=1159753747]this was exactly what i needed, did you know about this?[/quote]Yes. The original link I gave you included javascript equivalents, and one click away from it would have given you an exact duplicate of your code with javascript. I'm glad you solved ypur problem. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 another problem.the script that i send the form to emails me the data and now redirects depending on which value was chosen.right now its only sending the mail and not redirecting.. does that have anything to do with it having two things to do? can it only handle one? any solutions here? Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 Are there any more requirements for this form processing script?Typically, retrieve the data sent by the form; validate it/do whatever you want with it; construct the email message; send email message; branch to whatever location you want depending on the value of something from the form. Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 still isnt working.... Quote Link to comment Share on other sites More sharing options...
tomfmason Posted October 2, 2006 Share Posted October 2, 2006 You could use Ajax for something like this. Here is the javascript.[code=php:0]function createRequestObject(){ if (window.XMLHttpRequest) { // Mozilla, Safari, Opera... var xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { // IE try { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!xmlhttp) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } return xmlhttp;}var http = createRequestObject();function sendRequest() { var field = document.getElementsByTagName('nameOfField').value; http.open('POST', 'yourmailscript.php'); http.setRequestHeader('Content-Type', 'application/x-www-form-urlencode'); http.send('field=' + field); http.onreadystatechange = handleRequest();}function handleRequest() { if (http.readyState == 4) { //the response from the mail script. var response = http.responseText; if (response == 'sent') { redirector(); } else { alert('There was an error in sending the mail'); } }}//this will redirect the user as neededfunction redirect() { var field = document.getElementsByTagName('nameofInputField').value; if (field == 'something') { window.location = 'http://www.something.com/something.php'; }else if (field == 'something else') { window.location = 'http://www.somethingelse.com/whatever.php'; } else { alert('invalid location'); }}function blockSubmit() { sendRequest(); return false;}[/code]Now in the form you could do something like this..<form action="" onSubmit="return blockSubmit();"> <!-- your drop down menu --><input type="button" value="Submit" onClick="sendRequest();" /></form>Now in your php script that receives the information from the script above. You could do something like this.[code=php:0]$field = strip_tags($_POST['field']);//now you send your emailif (mail($to, $subject, $message, $headers)) { echo "sent";}else{ echo "error";}[/code]Hope this example helps..Tom Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 [quote]the form will be something like this[/quote][quote]this was exactly what i needed[/quote][quote author=jwk811 link=topic=110189.msg444997#msg444997 date=1159758291]still isnt working....[/quote]Do we get to see your code, or should we continue to guess? Quote Link to comment Share on other sites More sharing options...
jwk811 Posted October 2, 2006 Author Share Posted October 2, 2006 Heres the form:[code]<table><tr><form action="process.php"><td style="font-size: small"><b>Method</b></td><td><input type="radio" name="1" value="1"><option>Live Chat</option><input type="radio" name="2" value="2"><option>Checkout Lane</option></td></tr><tr><td><input type="submit"></td></tr></table></form>[/code]And heres the process script[code]<?phpif(isset($_POST['page'])){switch($_POST['page']){case 1:header("Location: http://www.boldchat.com");break;case 2:header("Location: lane.php");break;}}?>[/code]When the form is submitted it just goes to the process page and doesnt do anything else. Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 2, 2006 Share Posted October 2, 2006 If you omit the method from the form opener, it defaults to method="get". You can either test the $_GET array in your second script, or change the form opener to include method="post". 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.