สอบถาม javascript append text ครับ

เริ่มโดย DewChelsea, 12 พฤษภาคม 2014, 20:27:45

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

DewChelsea



กด generate โดยใช้ php
แต่ผลการแสดงมันไม่เข้าไปใน formอะครับ

Code Form ประมาณนี้ครับ :
<br><div id=\"contents\"><textarea  name=\"content\" rows=\"10\" cols=\"100%\"></textarea></div><br>

กดปุ่ม submit แล้วมันไม่เข้าไปใน form นี้คับ ลองใช้ .js ก็ไม่แสดงผลอะครับ
รบกวนผุ้รุ้ทีนะครับ  :-[

TOO 'GETHER


ANALOGY

ขอดูโค๊ดทั้งหมดเลยได้ไหมครับ แบบนี้มันบอกไม่ถูกอะครับ

O.o!!


DewChelsea

ตอนแรกเป็นงี้ครับ ก่อนกดปุ่ม Submit



แต่พอกดแล้วจะเป็นเหมือนรูปนี้ครับ



ซึ่งผมอยากให้ ตัวหนังสือที่ generate มาได้ ไปอยุ่ใน textarea แต่มันดันไปอยุ่ล่าง Text Area

คำถามก็คือ

ผมจะต้องเขียน .js ยังไงครับ ตัวหนังสือที่ gen ออกมา จะไปอยุ่ใน Text Area นะครับ

Code :
<?php


add_action
'admin_menu''my_plugin_menu' );


function 
my_plugin_menu() {
add_options_page'List All URLs''List All URLs''manage_options''list-all-urls''generate_url_list' );
}


function 
generate_url_list() {
if ( !current_user_can'manage_options' ) )  {
wp_die__'You do not have sufficient permissions to access this page.' ) );
}

$i 0;
$myposttpe = array(); // Creating array variable to house all custom post types
$mypostname = array(); // Creating array variable to house all pretty names custom post types


// Get all Custom Post Types, and ONLY Custom Post Types. See http://codex.wordpress.org/Function_Reference/get_post_types
$args=array(
  
'public'   => true,
  
'_builtin' => false
); 
$output 'objects'// names or objects, note names is the default.
$operator 'and'// 'and' or 'or'
$post_types get_post_types($args,$output,$operator); 


// Loop through get_post_types and create arrays for custom post type names and labels  
foreach ($post_types  as $post_type ) {
$myposttpe[$i] = $post_type->name// Getting the code name for the post type. See http://codex.wordpress.org/Function_Reference/get_post_type_object
$mypostname[$i] = $post_type->labels->singular_name// Getting the pretty name for the post type.
$i++;
}

$arrlength count($myposttpe); // Setting variable arrlength equal to the number of array units in $myposttpye



// Form and function called on submit sourced in part from http://stackoverflow.com/questions/6060028/call-form-submit-action-from-php-function-on-same-page
?>


<p><strong>Select the URLs you would like to list from the following options:</strong></p>
<form id = "myform" action = "" method = "post">
    <input type="radio" name="getpost-radio" value="all"/> All URLs (pages, posts, and custom post types)<br>
    <input type="radio" name="getpost-radio" value="pages"/> Pages Only<br>
    <input type="radio" name="getpost-radio" value="posts"/> Posts Only<br>
    <?php
for($x=0;$x<$arrlength;$x++) {
  echo '<input type="radio" name="getpost-radio" value="'$myposttpe[$x] . '"/> ' $mypostname[$x] . ' Posts Only<br>';
  }
     
?>

    <br>
    <input type="checkbox" name="makelinks" value="makelinks"  /> Make the generated list of URLs clickable hyperlinks <br>
    <br>
   
    <input type="submit" class="button-primary" value="Submit"/>
<br><textarea  name=\"content\" rows=\"80%\" cols=\"100%\"></textarea><br>

</form>

<?php
if (isset(
$_POST['getpost-radio'])) {

    if ($_POST['getpost-radio']=="all") { 
$the_query = new WP_Query( array('post_type' => 'any''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else if ($_POST['getpost-radio']=="pages") {
$the_query = new WP_Query( array('post_type' => 'page''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else if ($_POST['getpost-radio']=="posts") {
$the_query = new WP_Query( array('post_type' => 'post''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else {
for($y=0;$y<$arrlength;$y++) {
  if ($_POST['getpost-radio'] == $myposttpe[$y]) {
echo '<p>test</p>';
$the_query = new WP_Query'post_type='.$myposttpe[$y].'&posts_per_page=-1&post_status=publish'); 

}
}


?>



    <?php // The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>


<?php if (isset($_POST['makelinks'])) { ?>
<a href="<?php the_permalink();?>"><?php the_permalink(); ?></a>
                <?php }else { ?>

<?php the_permalink(); ?>,<?php the_title();?><br>

<!--<br><div id=\"contents\"><textarea  name=\"content\" rows=\"10\" cols=\"100%\"><?php the_permalink(); ?>,<?php the_title(); ?></textarea></div><br> -->
<?php ?>
   
    <?php endwhile; ?>

<?php // end if

// end generate_url_list() 

canvcom

#5
ใช้ jquery ดีกว่า

Surakrai

ไม่มต้องใช้ javascript ก็ได้นิครับ
ลองแบบนี้ดูครับ ตอนวนลูป ก็เก็บ title permalink ไว้ แล้วค่อย echo ออกมาทีเดียวใน textarea

   <?php // The Loop
      while ( $the_query->have_posts() ) :
         $the_query->the_post();
         ?>

      <?php if (isset($_POST['makelinks'])) { ?>
            <a href="<?php the_permalink();?>"><?php the_permalink(); ?></a>
               <?php }else { ?>
               
            <?php  $content .= get_permalink();?>
                               <?php  $content .= get_the_title();?>
               <!--<br><div id=\"contents\"><textarea  name=\"content\" rows=\"10\" cols=\"100%\"><?php the_permalink(); ?>,<?php the_title(); ?></textarea></div><br> -->
               <?php } ?>
   
   <?php endwhile; ?>

<div id="contents"><textarea  name="content" rows="10" cols="100%"><?php echo $content  ?></textarea></div>

O.o!!

ตามคุณ surakrai ก็ได้ครับ

ไม่ก็ลองดูนี่ก็ได้อีกวิธี




<?php


add_action
'admin_menu''my_plugin_menu' );


function 
my_plugin_menu() {
add_options_page'List All URLs''List All URLs''manage_options''list-all-urls''generate_url_list' );
}


function 
generate_url_list() {
if ( !current_user_can'manage_options' ) )  {
wp_die__'You do not have sufficient permissions to access this page.' ) );
}

$i 0;
$myposttpe = array(); // Creating array variable to house all custom post types
$mypostname = array(); // Creating array variable to house all pretty names custom post types


// Get all Custom Post Types, and ONLY Custom Post Types. See http://codex.wordpress.org/Function_Reference/get_post_types
$args=array(
  
'public'   => true,
  
'_builtin' => false
); 
$output 'objects'// names or objects, note names is the default.
$operator 'and'// 'and' or 'or'
$post_types get_post_types($args,$output,$operator); 


// Loop through get_post_types and create arrays for custom post type names and labels  
foreach ($post_types  as $post_type ) {
$myposttpe[$i] = $post_type->name// Getting the code name for the post type. See http://codex.wordpress.org/Function_Reference/get_post_type_object
$mypostname[$i] = $post_type->labels->singular_name// Getting the pretty name for the post type.
$i++;
}

$arrlength count($myposttpe); // Setting variable arrlength equal to the number of array units in $myposttpye



// Form and function called on submit sourced in part from http://stackoverflow.com/questions/6060028/call-form-submit-action-from-php-function-on-same-page
?>


<p><strong>Select the URLs you would like to list from the following options:</strong></p>
<form id = "myform" action = "" method = "post">
    <input type="radio" name="getpost-radio" value="all"/> All URLs (pages, posts, and custom post types)<br>
    <input type="radio" name="getpost-radio" value="pages"/> Pages Only<br>
    <input type="radio" name="getpost-radio" value="posts"/> Posts Only<br>
    <?php
for($x=0;$x<$arrlength;$x++) {
  echo '<input type="radio" name="getpost-radio" value="'$myposttpe[$x] . '"/> ' $mypostname[$x] . ' Posts Only<br>';
  }
     
?>

    <br>
    <input type="checkbox" name="makelinks" value="makelinks"  /> Make the generated list of URLs clickable hyperlinks <br>
    <br>
   
    <input type="submit" class="button-primary" value="Submit"/>
<br><textarea  name=\"content\" rows=\"80%\" cols=\"100%\">
<?php
if (isset(
$_POST['getpost-radio'])) {

    if ($_POST['getpost-radio']=="all") { 
$the_query = new WP_Query( array('post_type' => 'any''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else if ($_POST['getpost-radio']=="pages") {
$the_query = new WP_Query( array('post_type' => 'page''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else if ($_POST['getpost-radio']=="posts") {
$the_query = new WP_Query( array('post_type' => 'post''posts_per_page' => '-1''post_status' => 'publish' ) ); 
} else {
for($y=0;$y<$arrlength;$y++) {
  if ($_POST['getpost-radio'] == $myposttpe[$y]) {
echo '<p>test</p>';
$the_query = new WP_Query'post_type='.$myposttpe[$y].'&posts_per_page=-1&post_status=publish'); 

}
}


?>



    <?php // The Loop
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>


<?php if (isset($_POST['makelinks'])) { ?>
<a href="<?php the_permalink();?>"><?php the_permalink(); ?></a>
                <?php }else { ?>

<?php the_permalink(); ?>,<?php the_title();?><br>

<!--<br><div id=\"contents\"><textarea  name=\"content\" rows=\"10\" cols=\"100%\"><?php the_permalink(); ?>,<?php the_title(); ?></textarea></div><br> -->
<?php ?>
   
    <?php endwhile; ?>

<?php // end if

// end generate_url_list() 
?>

               </textarea><br>

</form>



DewChelsea

ขอบคุณทุกคำแนะนำนะครับ ได้แล้ว ดีใจมากครับ  :-[

ขอบคุณคร้าบบบบ  :'(