0

So, I have this button where you type the title and press on "create", here is a photo: enter image description here

Here is the code:

<div class="input-group margin">
                <div class="input-group-btn">
                  <button type="button" name="artButton" data-toggle="modal" data-target="#createArticle" class="btn btn-danger">Create</button>
                </div>
                <!-- /btn-group -->
                <input type="text" class="form-control" id="artTitle" name="artTitle" placeholder="Article title">
              </div>

    </div>

What I tried was to surround it with two form tags as POST method and then use $_POST['artTitle'] to echo what the user inserted in the other input but it didn't work.

So basically, when you press on create, a modal shows up asking for information regarding the topic, and I want the title to autofill if you type it in that field before pressing create..., and it doesn't work...

Here is how I tried to add the value to the other input

<?php if(isset($_GET) && array_key_exists('artButton',$_GET)): ?>
                <div class="form-group">
                  <label for="createArticleTitle">Title:</label>
                  <input type="input" class="form-control" value="<?php echo $_GET['artTitle']?>" id="createArticleTitle" name="createArticleTitle" maxlength="80" placeholder="Insert Article Title...">
                </div>
                <?php endif; ?>
5
  • Does your button click posts the form? Commented Apr 26, 2017 at 5:23
  • you said your using POST method then why your trying to get value from GET method Commented Apr 26, 2017 at 5:23
  • That would just work once and it will lead to a lot of page refreshing. better use some javascript library. select2.github.io/examples.html#data-ajax Commented Apr 26, 2017 at 5:24
  • @JYoThI I tried GET meanwhile..., first try was with post Commented Apr 26, 2017 at 5:28
  • try my answer @Andrei Commented Apr 26, 2017 at 5:37

1 Answer 1

1

I think you need after click create article field autofill in modal too . just use onlick event like this

$('#btnclick').click(function()
{
  // alert($('#artTitle').val());
   $('#article1').val($('#artTitle').val());

});
<form>
<div class="input-group margin">
                <div class="input-group-btn">
                  <button type="button" name="artButton" data-toggle="modal" data-target="#createArticle" id="btnclick"class="btn btn-danger">Create</button>
                </div>
                <!-- /btn-group -->
                <input type="text" class="form-control" id="artTitle" name="artTitle" placeholder="Article title">
              </div>

    </div>
    
 </form>   
 
 <head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div class="container">
  
  <!-- Trigger the modal with a button -->
<!--  <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> -->

  <!-- Modal -->
  <div class="modal fade" id="createArticle" role="dialog">
    <div class="modal-dialog">
    
      <!-- Modal content-->
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">Modal Header</h4>
        </div>
        <div class="modal-body">
          <p>Input atricle name<input type="article" id="article1" /></p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
      </div>
      
    </div>
  </div>
  
</div>

</body>
</html>

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks alot :D, should use js more often
Glad to help you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.