Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Write action without '

  1. #1
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Write action without '

    Is it possible anyway to write this html/javascript without the use of single hyphen? (' ')
    Perhaps a separate javascript function? The 'writeform.php' is causing problems with a following php script...

    HTML Code:
    <input  
     type="button" class="px10" 
     onclick="this.form.action='writeform.php'; this.form.submit();"  
     value="Import" 
    >

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    yes it is possible, but you would need to escape all of the double quotes with a backslash ( \ )

    Code:
    <input type=\"button\" class=\"px10\"
    ...
    >

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Which is one reason among several that you should always break out of PHP parsing mode when outputting HTML or any other sort of complex data.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    he's talking about parsing in javascript not php

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, s/he has a statement such as:
    Code:
    print '<input';
    print ' type="button" class="px10"';
    print ' onclick="this.form.action='writeform.php';'
    print '  this.form.submit();"';
    print ' value="Import"';
    print '>';
    ... which isn't working because of the single quotes around 'writeform.php.' It would be better written as:
    Code:
    ?>
    <input  
     type="button" class="px10" 
     onclick="this.form.action='writeform.php'; this.form.submit();"  
     value="Import" 
    >
    <?php
    It would be even better if you didn't use the Javascript at all: try a type="submit" input element:
    Code:
    <input
      type="submit"
      class="px10"
      name="action"
      value="Import"
    >
    ... then check if($_REQUEST['action'] === 'Import') in the page to which it submits, perhaps calling writeform.php if necessary. That class="px10" also look as if you might have something like:
    Code:
    .px10 {
      width: 10px;
    }
    If that's so, don't a) use pixels to size elements containing text or b) use class names that describe their style. Class names should be semantic and refer to the elements that they style, e.g. "submit-button".
    Last edited by Twey; 09-08-2007 at 11:15 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    What I am doing is using a php that writes html code to a html file:

    Code:
    $stringData = 
    
    ' HTMLCODE ';
    The single quotes breaks the $stringData variable...

    Boogyman, do you mean like this?

    Code:
    <input  
     type=\"button\" class=\"px10\" 
     onclick=\"this.form.action=writeform.php; this.form.submit();\"  
     value=\"Import\" 
    >
    The px10 class is for the font size.

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    What I am doing is using a php that writes html code to a html file:
    Well, you have two obvious options for readability, then: one is output buffers:
    Code:
      ob_start();
    ?>
    <input
      type="submit"
      class="px10"
      name="action"
      value="Import"
    >
    <?php
      $stringData = ob_get_clean();
    and the other is the heredoc syntax:
    Code:
    $stringData = <<<EOF
    <input
      type="submit"
      class="px10"
      name="action"
      value="Import"
    >
    EOF;
    The former is often easier because the latter still parses variables and such in the value. Either way, you should still be performing this check server-side, not using Javascript.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Jun 2007
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Could I create a function without single quotes that then is called by the onclick? Have tried a bit but can't get it to work...

    Code:
    function submitformSIE()
    {
      this.form.action="writeformsie.php";
      return true;
    }
    Code:
    <input type="button" name="button2" id="button2" onclick="submitformSIE()" value="Button" />

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hey, are all my posts in this thread invisible?

    1. You don't need and shouldn't use Javascript here.
    2. Even if you did need to use Javascript, you don't need to and shouldn't be enclosing the whole thing with ugly quotes.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Twey's suggestions are good ones.

    Using javascript when you don't need it is at best limiting some viewers on your page from submitting. It's also not secure.

    Anyway, you can always escape quotes, in javascript, PHP, etc.

    'Shouldn\'t be hard to do like this'
    "or, \"Like this!\", I said..."

    You can't simply write the javascript "without" the quotes, since that would cause random characters to be output which would be worthless to the browser (or even cause some strange reaction).
    But you can, using the correct methods, display this using PHP.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •