Form submission

Well, Searls03, I will look at your code later today in detail.

But, first, again, PHP code can only be executed once when the code is loaded. So, when you say “refresh” you can not get the PHP code to do anything. Once the page is loaded into the browser, the PHP code no longer exists.

A simple proof of this and a way to view your REAL code after the PHP disappears, just right-click on your page and VIEW-SOURCE. You will see the code after PHP is gone. Perhaps in that you will be able to see your mistake.

But, with that said, you can refresh a DIV or iFrame using javascript. Only the iFrame will except the external PHP code. (Which fakes a reload of the page, but, only inside the iFrame.) Later today, I will tear you code apart and see what we can do.

but the thing is, that code shouldn’t need to really use php, only to get the values for the drop down. I can’t get it to submit to the ajax is the problem. I would still like some examples if you could :slight_smile:

Perhaps I am not explaining it correctly. PHP is SERVER-SIDE code. It must run on the server.
So, in my samples above, the PHP file is server-side. It is a file you call from the html file. The data
you send to it, such as a cart ID tells it what data to return to you. In can include just data, but, then
you have to move it on your page. (Moving it with Javascript to the correct div or text fields.)

IN the html file, there is a small Javascript which reloads the iFrame with the PHP file…

SO, the php file uses the cart-ID and creates your table with all of the info in place and totalled up.
It echo’s this table or whatever and that is what show inside the iFrame.

I should be home tonight and can help create a sample code for you again if you need it. Let me know if this explained it any better…

I don’t think that is what my problem is though. I have this ajax/javascript:

[code][/code]
THis form here should submit to it without problem:
[php]

 

 

Multiple Select with Groups <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row5 = mysql_fetch_array($sql)){ $product = $row5["product"]; $id =$row5["id"]; $price =$row5["price"];

?>

      <option value="<?php echo $product; ?>"><?php echo $product; ?></option><?php

}
?>

    </select>
  </div>
</div>

<h2>&nbsp;</h2>
[/php]

even if I take away the php in the code and just put a static value, it still does not work. does this make more sense as to what my issue is?

Very sorry about this bad news, but, your sample code is incorrect in so many places,
I don’t know how to explain it. First, several code groups starting with a ‘{’ do not end… I have told you this, but, you can’t seem to see it.

Let’s try one more time… If you have this code:

<?PHP (Start PHP) if(...){ echo "xyz"; echo "123"; ?> (End PHP)

<SELECT …> (and then have html), then the code never ends. The “if” will execute the xyz-echo and end. It never makes it to further code later on. Then, you have more php code and eventually close the group, but, it never really closes. So a lot of your code never get’s executed.
Usually, you would do this this way:

<?PHP if(...){ echo "xyz"; echo "123"; echo "/n"; } ?>

You see the HTML is printed BY YOUR PHP and ALL your code get’s executed…

Also, You have a form set up, but, it is NOT in the body of the html page. As far as I know a form will not post without it being inside the body of the html page. And, lastly you can not mix up javascript and php the way you are doing it. You may be getting it to do some sort of refresh, but, who knows what routines are being called.
To prove this, when you open this page from the internet, RIGHT-CLICK on it and select VIEW-SOURCE. Then, look at this code and see what you actually have as a posted page OUT OF your PHP page. You will see no PHP code in it. (Unless a javascript routine stored some there, but, it is not executable that way!)
So, this means you should start over with a standard form and standard PHP routine and get that to work first. Then, bring in some of your Javascript or Jquery and change things little by little…

Sorry for all that disappointing news…

could I get some of those iframe sample codes?

Sure, it is all in Post#8 of this thread. Just go back a page and read it. Ask any questions you need to.

Remember that it uses a hidden iFrame and loads a PHP file into it. Once that is done, the data from the PHP code can be accessed. I usually just use a hidden field and load data into it from the PHP code. Once the data is inside the hidden field as “value=”, then Javascript can move it to wherever you want it or manipulate it further. Give it a try…

I meant some of those example pages you said you would put together…

could you also help me with the this code:
[php] [/php]

where the form submits to the ajax so the page doesn’t reload to submit form? clearly I am having a problem with it. could you help me fix it?

Searls03, of course we will help. But, still a little mixed up on your programming. You could use AJAX with is really an acronym for Asynchronous JavaScript and XML. Which means you would use JavaScript and access the database thru XML or JSON or JQUERY. I use PHP to access the database as I feel it is more secure.

I am heading to bed, but, in the morning I will try to help you sort it out.

But, until then, can you layout some simple idea of why you want to do all this. What is your project? Just give us an idea of where you are heading with all this. If it is for something we already have programmed, we might be able to speed up this process. Thanks for filling us in a little…

I am working on a POS system…kinda(don’t ask). anyways, when the drop down changes, I need the form to submit without the page reloading. I do need the divs called price and total to reload because those are the shopping cart area. I have it working with other forms, but can’t get it to work with this one.

I would still likes some sample pages on the iframe for other issues too:)

It does not matter what kind of POS system you are creating. But, since it involves money and CART’s, you do NOT want to use Javascript or HTML to access or dynamically update your page. The reason is that is client-side and can be hacked. Ajax can work with the correct security in place. What I was trying to explain earlier and gave code to explain, was using PHP from the SERVER-SIDE. This can be “refreshed-dynamically” by calling the PHP into a hidden iFrame. IFrame can hold any webpage. Loading this iFrame from a PHP page means that the database is accessible by PHP.

Let’s explain this in a very simple way. The standard way to call a PHP script and have it get data from your database is to use a form. The form, would have, let’s say the CART number you want to view. The ACTION on the form would be the PHP file that would use $_POST to grab the CART number and look up that data. That data would, of course, be in PHP variables. To view this data, the PHP file would then display (echo/print) the data in HTML format.

This way works well for most. It hides the database structure, the code to access the database, etc. You only see what the PHP code allows you to. Math functions can be done in the PHP or later in your Javascript code which runs SERVER-SIDE. All good! Easy to understand. I am sure you understand all this.

Now, to add in a refresh or dynamic-refresh, you run into issues. First, how can you run PHP code SERVER-SIDE without refreshing the current page. You either set up a complicated Javascript with Ajax, JSon, JQuery or other tools making the project very complicated. Which part is causing the refresh errors??
OR, just load a small PHP file into a hidden area on the live form page and access the data from there. The new PHP file will just use a passed CART number and pull the data from the database. Then, it puts the requited data into simple hidden fields. These can be textboxes textareas, whatever you need. Since it is hidden, users can not see them. (They are readable if you view source.) Since these are normal HTML fields, they are useable in any standard code such as Javascipt.

So, now that I have recapped what I have been suggesting, have you any quick questions as I drum up a sample to show how it works? My code will be simple and do little with a database as I do not know your layout. If you understand all of these comments, let me know before I post code…

I understand fairly well. Is what you are telling me that the page wont’ refresh still? this is what I want.

No, I am not saying it will not refresh. I am saying you either have to use PHP and load it into an iFrame and use the data there to refresh OR write SERVER-SIDE Javascript maybe with JSON/JQUERY/AJAX tools to get into the database to refresh the page. You were using parts of both.

Here is a page that demo’s DYNAMIC IFrames. Skip down to where you see the OUTPUT PAGE1 and PAGE2 lines just above ad picture. Press the PAGE2 text and all of a sudden the page will change without moving much. The background will turn yellow. This is a simple DYNAMIC Javascript code. Press on PAGE1 and it will change back. This is simple. BUT, you can do this WITH PHP by adding it into the frame. At that point the data PHP sends back to the browser would be INSIDE the frame and useable from Javascript.

OR, you have to use SERVER-SIDE Javascript which works too. Here is a site that explains this type of code. It shows how to access database (MySQL) from Javascipt.
https://developer.mozilla.org/En/Server-Side_JavaScript/Walkthrough

did you link the sample? or is part of the other link? I get what you are saying now. thank you.

I mainly got what I want working to work. one question though…how do i set two values for the function in this?

ie<input type="button" name="submit" value="update" onclick="update(<?php echo $id; ?>)" />

and then pass both to this for the get?
[php] [/php]

specifically I want it to go to ?q=id&price=price&qty=qty. I need to know how to basically make the function submit that data.

Cool that you are making headway. I have a trick I use to pass more than one option value from PHP to Javascript. It works well as long as the data you are passing is not too long. You basically combine the two or three arguments into one inside of the drop-down. Then, inside the Javascipt, you divide this info back up.

So, in your button, you can use ID=“update” and access this in Javascipt by getElementById,
Use the VALUE= and place the multiple arguments here. Separate them with the ‘|’ bar character. (Seldom used for anything!) something like this:
<input type=“button” name=“submit” value="<?php echo $arg1 . "|" . $arg2 ?> " onclick=“update(<?php echo $id; ?>)” />

Then, when the routine is sent to Javascript the arguments can be decoded by this:

var productArguments = document.getElementById(‘update’).value.split(’|’);
var arg1 = productArguments[0];

etc… Or, you could actually change what is passed to the ONCLICK and add the extra fields there. Then, in the javascript breakdown what is sent back instead of using the VALUE option.

Maybe you can get that mess. Sorry, rushing off for the evening and trying to get it all down for you. I will check in about 5-6 hours as see if you figured it out. Remember, IT IS DO’able… somehow… LOL

but I need to know how to make it so that the values in the form are what should be there, ie I can update a value via a text field.

Quantity $
<input type="button" name="submit" value="update" onclick="update()" />

something similar to this. I need the values in the text fields to be the conditions…

Sponsor our Newsletter | Privacy Policy | Terms of Service