Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. What kind of variables? You haven't mentioned anything like that at all so you are confusing me. If you have something that you created in the script that is sending this form to the user you could hide those values in 'hidden' input tags that would then be part of the POST array. echo " <form> --- --- ---- <input type='hidden' name='valuea' value='$valuea'> --- --- </form> "; If you added an input tag to your form tag you could assign a php variable to it as a value= with a name that you could then retrieve it from POST with.
  2. To be clear. I gave you a set of html code that is the form your user will see and make his choice from. Look at it an understand it. Then look at the previous PHP code that shows you how to handle the input from the user and that then calls the selected script. Be sure to include the part I revised from checkboxes to radio buttons. If you want I can give you an entire script that does this, but I figured you'd want to use these pieces in your own script. But...
  3. I gave you all of the code you need to do that. Are you not reading it?
  4. Yes - 2 posts ago I suggested switching to radios and then I posted the code to change to that. I realized that problem too late.
  5. Feeling creative so here is a sample of how I would do the entry form: echo "<div id='form_box' style='width:40%;border:2px solid blue;padding:10px;'>"; // suggestion: learn how to use CSS and move the above styling to that area echo " <form method='POST' action=''> Choose which form you want to see by clicking on a button. <br><br> <label>Show Form #1 <input type='radio' name='form_sel' value='1'> </label> &nbsp;&nbsp;&nbsp; <label>Show Form #2 <input type='radio' name='form_sel' value='2'> </label> <br><br> <center> <input type='submit' name='btn' value='Show Form'> &nbsp;&nbsp;&nbsp; <input type='submit' name='btn' value='Return to Caller'> </center> </form> "; echo "</div>"; Now the input choice is named 'form_sel' so the previous php code needs this change: $formname = ''; if ($_POST['form_sel'] == '1') $formname = 'form1.php'; if ($_POST['form_sel'] == '2') $formname = 'form2.php'; Replace the part that checks for checkbox1 and checkbox2 with the above. This makes sure that the user can only make one selection whereas the use of check boxes would not.
  6. Upon further review - you might wanna use radio buttons instead of checkboxes.
  7. The code tag that I mention is used ON THIS PAGE when you post code for us to read. Makes it easier to focus on the written code that you are showing us. It looks like this: <> . Copy and paste your code sample that you want to show us and then click on the <> icon here and in the window that opens up you can paste your sample and then click on the 'insert in post' and it then shows up here in a highlighted box and then you can write your own text to ask about it or whatever.. If you look at other posts/topics I'm sure you will see how it is being used by everyone. As for the question you are trying to handle. My suggestion was to make this current form a simple one that only want the user to give you this response you are seeking - the number or perhaps better, a choice of one text label or another or maybe a couple of checkboxes and a submit button. Then have this current script read what was submitted and from that do this: if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formname = ''; if (isset($_POST['checkbox1'])) $formname = 'form1.php'; if (isset($_POST['checkbox2'])) $formname = 'form2.php'; } if ($formname <> '') { header("Location: $formname"); exit(); } else { header("Location: thisform.php"); // redisplay this form exit(); } What this code does is process the input and call the next form that you want to execute. If the user did not check either box then it redisplays this page for them to do it again. You'll need to add some code to present an error message perhaps to tell the user to check one of the boxes. BTW - do you have error checking turned on to show you simple syntax errors and such? error_reporting(E_ALL); ini_set('display_errors', '1'); Add this to to the start of all of your scripts. Once you have debugged it all and it is running fine you can remove it or change the ini_set to a 0. PS - This post used the <> icon twice to present the two blocks of code I showed you. See how nice it appears? PPS - Be SURE that you copy&paste your sample code and do NOT re-type it here. Time and again something gets re-typed incorrectly and eventually the user admits that he/she has made such a mistake and we will have wasted our time solving the wrong issue.
  8. Yes - it is quite simple. Correct your tags as I mentioned and use this form to ask the user to provide a number. Tell the form tag to come back to this script. Have this script check if it was properly submitted (check for method = post or the button name was proper) get the number from the form elements. If that value is correct then pass it through to the if statement that decides what form to jump to. Take that answer and do the following: header('Location: '.$url); exit(); where $url is the string you assemble in this script to go to the page you want to display. Note the exit() statement. It is recommended to use one here. HTH!
  9. 1 - once again - please use the code tags to post code 2 - you have mixed in the js code with php code and html code. Gotta change those habits. 3 - this cannot possibly run for you since your references to unknown as of yet variables won't show anything in the js code. 4 - you should not be using php vars inside js code. That is all I can say since even trying to organize your code into something that I could make sense of (very incomplete!) gave me heartache. Please - if you want us to look at why your code is not performing as you expect show us what you are looking at. Plus - look at the proper syntax for a <button> tag. You are not using it. Personally I like to use <input> tags for my submits, not the <button> one. Your use of the word 'input' inside a <button> tag makes no sense. The way to solve your dilemma is (I'm guessing here) to let this form handle sending out the selection screen and responding to it and getting whatever number was input and using that to jump to the page you want instead of using JS to do it.
  10. No - I hope I'm not wasting your time. You need to do a little reading up on how to use functions. And look for references to 'scope' which will explain how variables work in and outside of functions. PS - when one writes a function it is either to put a block of code into one place so that it can be run multiple times from more than one place so that you don't have to "re-create the wheel". One good thing to make use of is how a function can return a value when it is done. Sometimes the function is written to actually produce that value so you need to return it. Other times it simply does something for you and you should probably return an answer that tells the rest of your code whether the function was successful or not. Your current code simply calls the function but doesn't return anything. Sure - it does an exit with an error message but you might want to re-think that or at the very least understand how they work for future reference. Currently: $senddata = "122222"; $serial->sendMessage("$senddata\r"); checkInput($senddata); you are doing the above. Note that there is no value coming back from the call to CheckInput. A better way to design your script would be to complete the function by issuing a "return $answer" line and catch that with the calling line being "$result = checkInput(Ssenddata);" and then checking that $result to see how to proceed.
  11. Well - I told you what is wrong with your function. You have to fix those issues to get 'past' this error. Simple as that. Try passing them into the function when you call it? As for this latest block of code - I don't see a reference to CheckInput so it means nothing to us.
  12. OK - I cleaned up your function to be able to make better sense of it (nothing wrong) and this is what I see - Check the CAPS. function checkInput($stuff) // WHAT IS $STUFF USED FOR? Not in here. { $starttime = microtime(true); // WHERE ARE $READ AND $TIMEDIFF DEFINED - NOT IN THIS FUNCTION while($read == "" && $timediff < '5') { $read = $serial->readPort(); // WHERE IS SERIAL DEFINED - NOT IN THIS FUNCTION $substring = substr($read,0,1); if($substring == "-") { print"<CENTER><H2>We encountered an error when sending $read". "Please close window and try again</H2></CENTER>"; $noDataToSend = "False"; exit(); } $endtime = microtime(true); $timediff = $endtime - $starttime; if($substring == "+") { //if ACK received, reset timer $starttime = microtime(true); } else { if($substring != "") { echo "Substring " . "$substring\r\n"; } } if($timediff > '4') { print"<CENTER><H2>No response from the Station. Please close this window, check your serial connections and try again</H2></CENTER>"; $noDataToSend ="False"; exit(); } sleep(0.1); }//while } //end function Do you understand how functions work with variables? If one is not defined inside the function it has to be passed into it either as an argument (preferred) or as a global variable.
  13. I think we want to see the CheckInput function since that is what you have decided to alter. Please? Otherwise, why did you show us that you have modified that call to checkinput? Still sounds like you need to find where you assigned the string '11111' to $serial. But now that you are changing the call to checkinput to use a different argument now you are getting an error about using a null variable so you have not assigned anything to that new argument.
  14. If line 371 is in the checkinput function could you show us that function and indicate that line?
  15. Here is how the html could look. Much less complicated and no need for entering and exiting php mode over and over and over. //************************************* if ($display_section) { echo " <section class='page-section spt spb bg-light-gray cfilter-section'> <div class='wrap ml0 mw-970 mlra'> <div class='cfilter-inner'> "; if (!empty($filter_title)) echo "<div class='f18 fwb tac'>$filter_title</div>"; echo "<div class='filter-select-wraps'>"; if ($focus_select) echo $focus_select; if ($industry_select) echo $industry_select; if ( $org_select ) echo $org_select; if ($fifty_states_select) echo $fifty_states_select; if ($type_select) echo $type_select; echo "<select class='conf_speakers'> <option value='all'>All Speakers</option> <option value='speaker-f'>Fernandez</option> <option value='speaker-marcus'>Marcus Levine</option> <option value='speaker-am'>Andrew Michael</option> </select>"; echo "<div class='checkbox'> <input type='checkbox' id='top-conference' name='top-conference'> <label for='top-conference'>Top Conference</label> </div> <div class='filter-reset'> Reset Filters </div> <form method='POST'> <label class='switch' for='switch-1'> <div class='slider round'></div> <input type='checkbox' name='switch-1' id='switch-1' type='submit'> </label> <input type='submit' value='Salva' name='submitBtn'> </form> </div> </div> </section> "; } You have two type attributes on your checkbox tag. Fix You have an input tag outside of the form tag so that is meaningless. You need a 'name=' clause on all form input elements or else your php code won't find them. See your <select> tag. Note how I changed all of your uses of " and ' characters. If you begin a string with " then you can reference your php variables inside of them with no issue. If you begin with the single quote you have to worry about using a php var inside. Suggestion. Don't use upper and lowercase in PHP. It isn't necessary and since php is case-sensitive it can lead to problems when you mis-type the name somewhere in your code and can't figure out why you have a problem. Stick to all lowercase. Another suggestion. Do not use minus signs in your variable names. Use the underscore. Something like "$switch-1" looks like a statement of arithmetic instead of a variable name. Go with "$switch_1".
  16. Show us the html form. In its entirety. Then show us where you read the POST values in your php
  17. Feeling magnanimous today. Here is a VERY SIMPLE BARE BONES html page to show you what yours will have to have in order to provide you something to check and submit to your php script. Look thru it and read up on whatever you don't understand. It contains the basic html parts that all html pages need but only enough to do one thing for you for now. <!DOCTYPE html> <html> <head> <title>Untitled</title> <script type='text/javascript'> </script> <style type='text/css'> body { background-color:#c0c0c0; } #form_box { position:relative; float:left; width:30%; margin:2% 5%; padding:5px; border:2px solid blue; } </style> </head> <body> <div id='form_box'> <form name='form1' method='POST' action='' autocomplete='off'> <label>Show All? (Check for 'Yes'): <input type='checkbox' name='showall' value='Yes'> </label> <br><br> <center> <input type='submit' name='btn' id='subbtn' value='Submit' accesskey='s'> </center> </form> </div> </body> </html> (Note how the use of the <> icon above places the code I wrote into its own box. ) Besides the "form" code I added a tiny bit of CSS to help format the webpage which is something you will most likely want to learn to do as well. Play with the css and see how it changes your viewing. I left a space for future JS code should you get that advanced. You can ignore it for now. I placed the html code for the form inside a <div> tag which is something that you will also have to learn about as you build your web page with more elements or titles or text. Realize that this is simply the html code for showing your design to the user. You can click on the Submit button but nothing will happen since this form is not pointing to any script to run when you do that click. Once you get this html completed to show what you want you will give it an 'action' value to cause it to be processed by your php script. That's when you will have to learn the php portion of this exercise.
  18. PHP is a scripting language that allows you to write dynamic webpages that use html to display your ideas. That html is sent to the client and the user looks at it and clicks on html elements (tags such as <input> and buttons such as 'submit') which causes the page contents to be sent to a php script on the server which receives it and processes it. So far you have a php function that will do something for you but you first have to have some php code that receives the input data from the html, which you don't have. That is why I first asked you where is the rest of your html. So - if you want to have a webpage, work on that first which means you will need to read a bit on html coding. Look up the form tag, the different input tags and create a page that contains what you need. Find a sample of a simple html page and modify it to show your ideas. Then show it to us in PLAIN text form, not as an 'image'. And as already mentioned be sure to use the proper <> tag on this forum to present it. Start small and easy and then we'll proceed to the next stage.
  19. If your total html code consists of one checkbox element, how does it ever get passed to your php script?
  20. Is there html for the form and a submit for the trigger?
  21. I pointed this out earlier and it was mentioned by another poster here. The IF statement needs to be in parens and you are not doing that!!! If (something == something) { handle the true conditon } else { handle the false condition } That is how it is written.
  22. I think OP was distracted by my pointing at the braces and neglected the other half of my post...
  23. Do you really want to present a page with 1000 inputs on a page for your users to have to work with?
  24. Look at the parens. They are not matched. Also your Brace doesn't show and ending brace and you don't need parens for an echo statement. Does your host not offer you an administration tool such as cPanel to do this kind of work? Much easier than writing queries to do it.
  25. Show us your code where the errors are happening. Show us the error messages too.
×
×
  • 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.