4 Replies - 3703 Views - Last Post: 22 February 2013 - 05:05 PM Rate Topic: -----

#1 the_wire_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-February 13

Help me get my submit button to activate my PHP form (Dreamweaver)

Posted 22 February 2013 - 02:33 AM

I must say im a comeplete noobie, and got created a webpage with dreamweaver, and im ok with it.

But i have now created a post message field and the right .php file, but how do i link the two?

cant seem to get the submit button to read my .php file. how do i link the two ?
do i setup the button as a submit button, or the function none and then write the code my self ?

Hope someone will be able to help... have been stuck at this for days now ....

Is This A Good Question/Topic? 0
  • +

Replies To: Help me get my submit button to activate my PHP form (Dreamweaver)

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: Help me get my submit button to activate my PHP form (Dreamweaver)

Posted 22 February 2013 - 02:43 AM

View Postthe_wire_man, on 22 February 2013 - 10:33 AM, said:

cant seem to get the submit button to read my .php file. how do i link the two ?

you dont. the main reason being that your form is on the client and the PHP is on the server.

the problem resolves itself when you look up how (HTML) forms work.
Was This Post Helpful? 0
  • +
  • -

#3 the_wire_man  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-February 13

Re: Help me get my submit button to activate my PHP form (Dreamweaver)

Posted 22 February 2013 - 03:20 AM

now im just eaven more confused.. dont both parts have to be on the server ?

im pretty sure, i have got it all right.

i got my table with the info, name, phonenumber and email. and i got the right php file, i downloaded it as a template and altered the info so it is the same as on the table. now i just need to link the two parts together somehow. but i have no ida how to do that.

do i mention the .php file somewhere from the page with the table somewhere.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3572
  • View blog
  • Posts: 10,414
  • Joined: 08-June 10

Re: Help me get my submit button to activate my PHP form (Dreamweaver)

Posted 22 February 2013 - 05:17 AM

View Postthe_wire_man, on 22 February 2013 - 11:20 AM, said:

now im just eaven more confused.. dont both parts have to be on the server ?

thats a completely different question. PHP, HTML and JS are *stored* on the server (and hence served *from* the server) but the are *executed* differently. PHP is *executed* on the server while HTML and JS are *executed* on the client.
Was This Post Helpful? 0
  • +
  • -

#5 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: Help me get my submit button to activate my PHP form (Dreamweaver)

Posted 22 February 2013 - 05:05 PM

Think about it like this. PHP lives on the server. Your browser neither knows nor cares that the HTML is being generated by PHP. All the browser cares about is receiving valid(ish) HTML, CSS and Javascript. That's what the browser needs to show you the page. Once the browser has received that from the server, PHP is no longer involved; it has done it's job and is out of the picture.

In order to get information from the user/browser to the server, you need the browser to send that information back to the server. PHP can not access the info from the browser unless the browser sends it. That's what <form> elements do; they collect info from the user and then when they are submitted they send that data to the PHP script referenced in the "action" parameter.

Once the browser has sent the info to the server, your PHP code can process that info using by looking into the $_POST array. Every <input name="myText"> element in the HTML form will be represented in PHP by a $_POST["myText"] element, where the "name" of the input element is the name of the element in PHP.

So, say for example that you want to allow visitors to post message on a user profile, you could add a form like this to the profile page:
<form action="addComment.php" method="post">
    <input type="hidden" name="user_id" value="<?php echo $userID; ?>">
    <textarea name="message"></textarea><br>
    <input type="submit" value="Send Comment">
</form>


Note that in this snippet, I am assuming that the PHP code generating this page has the ID of the user who's profile it's showing in a $userID variable. That will then be insert into the form via a <input type="hidden"> element, which will then be sent to the server when the form is submitted along with the rest of the form.

So, the "addComment.php" page can process this form by accessing the $_POST array, like so:
<?php
if (!empty($_POST["user_id"]) && !empty($_POST["message"])) {
    // Lets assume that the following function does the
    // actual database stuff. I can't be bothered to do
    // all that in this example :)/>

    if (saveComment($_POST["user_id"], $_POST["message"])) {
        // Success! Go back to the profile page.
        header("Location: /profile.php?id=" . $_POST["user_id"]);
        exit;
    }
    else {
        // Error! Failed to save the comment. Show the user
        // and error message, or something.
        header("Location: /form_error.php");
        exit;
    }
}



Do you get what I mean?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1