1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to work PHP include file syntax within javascript?

Discussion in 'PHP' started by raj_as, Jan 18, 2013.

  1. #1
    Please help me guys...
    I want validate text box and redirect php file using java script...!
     
    Last edited: Jan 18, 2013
    raj_as, Jan 18, 2013 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    I want a milion euro's!? can you give it to me? LOL

    Please describe what you have done with examples to your works and what didn't work so we can help you figure out where you need help, i'm not going to put alot of time in just requesting a piece of scriping.

    So please show some code and things you triend and or have done!
     
    EricBruggema, Jan 18, 2013 IP
  3. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #3
    PHP runs on the server and creates the HTML, CSS and Javascript. It then sends this to the browser, where the Javascript runs. PHP isn't in the browser, so Javascript has nothing to do with PHP. As Eric said - what are you trying to accomplish? In English, not in programming terms.

    (To validate a textbox in Javascript, you just write Javascript to make sure that what's in the textbox is what you want - all digits, no digits, 2 or more words, a sane-looking email address, etc.)
     
    Rukbat, Jan 18, 2013 IP
  4. dropdrop

    dropdrop Active Member

    Messages:
    142
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #4
    do you mean like using Ajax ?
     
    dropdrop, Jan 24, 2013 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    Nothing at all to do with AJAX, although AJAX uses the same principles. Verifying user input is a two-step process. You validate what you can in Javascript, so you don't waste bandwidth sending obviously useless data to the server. Then you verify all input in PHP once it gets there. (For instance, you can't use Javascript to verify whether the email address the user gives you is a real email address, no matter how well it conforms to the standard, but you can verify that it contains '@' twice, which makes it invalid.)

    As far as 'redirecting' the PHP script (in the OP), that sounds as if it's dependent on the data, so PHP can determine that all by itself.
     
    Rukbat, Jan 24, 2013 IP
  6. dropdrop

    dropdrop Active Member

    Messages:
    142
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #6
    So it is like using regex on javascript code ? owh i see, agree with you! :cool:
     
    dropdrop, Jan 24, 2013 IP
  7. Dangy

    Dangy Well-Known Member

    Messages:
    841
    Likes Received:
    25
    Best Answers:
    2
    Trophy Points:
    155
    #7
    Use JQUERY, you can string a valid email address using REGEX by calling

    "var email = new regex(/sample/i,string);"
     
    Dangy, Jan 25, 2013 IP
  8. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #8
    Try using a javascript validation script so they must complete the form, after they do its sent to browser on submit and IF the variables have been completed it will redirect. The PHP code goes at the top and doesn't activate until the last variable in your form is present if($_POST['last_variable'])
    Then it runs the code block..and redirects. rather standard and basic.
     
    ezprint2008, Jan 26, 2013 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
    There's no form until it's sent to the browser. (Or did you mean it's sent to the server?)
     
    Rukbat, Jan 26, 2013 IP
  10. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #10
    right, its resent and browser/page is reloaded and activates the code and redirect upon next page reload.
    Which is standard in most forms that submit to self /page.
     
    ezprint2008, Jan 26, 2013 IP
  11. VideoWhisper.com

    VideoWhisper.com Well-Known Member

    Messages:
    330
    Likes Received:
    6
    Best Answers:
    2
    Trophy Points:
    113
    Digital Goods:
    2
    #11
    Redirect with:
    <script>
    document.location="http://redirect-url";
    </script>
    HTML:
     
    VideoWhisper.com, Jan 28, 2013 IP
  12. omgitsfletch

    omgitsfletch Well-Known Member

    Messages:
    1,222
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    145
    #12

    This is a VERY important point that many novice developers fail to implement. Javascript client-side validation is NOT enough. Javascript can be disabled, it can be edited, it can be bypassed. When the accuracy and integrity of your data must be correct, you must always rely on server-side validation, typically in conjunction with the initial JS validation.
     
    omgitsfletch, Jan 28, 2013 IP
  13. VideoWhisper.com

    VideoWhisper.com Well-Known Member

    Messages:
    330
    Likes Received:
    6
    Best Answers:
    2
    Trophy Points:
    113
    Digital Goods:
    2
    #13
    It's best to have core validation server side, mainly if this refers to site security and functionality.

    Javascript validation is mainly cosmetical and for fine tuning forms. Can be used for common errors so user's don't have to wait for page to submit and don't load your server with many useless requests.
     
    VideoWhisper.com, Jan 29, 2013 IP